What is wrong with this batch file code?

Here is the code:

@ECHO ON

set drive=%cd:~0,3%

xcopy *.jpg “%drive%folder /s /y /q”

xcopy *.jpeg “%drive%folder /s /y /q”

cmd

It looks for the folder “folder” in the f drive. The folder is there. How come I am getting this error? Is there a cmd to create a folder?

Aacini: Sorry if I spelled your name wrong. When I run the complete command:

@ECHO ON

set drive=%cd:~0,3%

xcopy *.jpg “%drive%folder” /s /y /q

xcopy *.jpeg “%drive%folder” /s /y /q

cmd

I get a “Cannot perform a cyclic copy.” error. I am running Windows XP 32 bit, and Service Pack 3. What can I do to fix the error? I am running the batch file from a flash drive.

Then how would you change the code so that it would copy all jpg’s and jpeg’s from the computer and then save them on the F drive. However, the drive will not always be in the f drive. It needs to copy from the computer to which ever drive the USB is in. How can I change the code?

3 Answers

  • This command:

    set drive=%cd:~0,3%

    get THREE characters of the directory; for example F:

    When you put %drive%folder there are two back-slash characters: F:folder

    use set drive=%cd:~0,2% or omit the in xcopy’s: %drive%folder

    Also, the quotes should enclose just the folder name, not the switches:

    xcopy *.jpg “%drive%folder” /s /y /q

    Regards…

    —————————————————————-

    EDIT:

    The cause: I bet you start your Batch file in a folder located INSIDE or in THE SAME “%drive%folder”. You can’t do that!

    The explanation: When you use /S switch in xcopy, the source files must be in a folder in ABOVE LEVEL with respect to the destination; otherwise, after created a folder and copy it, the process should go into this folder and copy it again in a never-ending process.

    Regards…

  • https://shorturl.im/rT0wI

    the big problem I see is that you can’t multiply floating point numbers in batch. in other words, you can only multiply integers. example: set weight=%userin%*”0.454″ You have 0.454 being multiplied by another number. Can’t be done in dos. BUT… if you wanted to multiply 454 buy it, and then at the end divide by 1000, you could do that. But there’s another thing wrong with your code: set weight=%userin%*”0.454″ should be: set /a weight=%userin% * 454 Don’t forget to include the /a.

  • Cannot Perform A Cyclic Copy

Leave a Comment