What is wrong with this batch file code?
Here is the code:
batch
@ECHO ON
set drive=%cd:~0,3%
xcopy *.jpg “%drive%folder” /s /y /q
xcopy *.jpeg “%drive%folder” /s /y /q
I'm trying to copy all JPEG files to a folder named “folder” located on the F drive. The folder exists, so I am unsure why I am receiving an error. Can anyone help me troubleshoot this issue? Additionally, is there a command that I can use to create a folder if it doesn't already exist? Thank you!
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.
Related Questions
Have you ever noticed how the rear wheel of a bike seems to follow the front wheel closely? Why does this happen, and is...
What does CSS stand for: Cybernet Slash Support or Cybernet Software Systems? I came across a company located in T. Naga...
I was watching the movie "Crimson Tide" and became curious about the ranks within a U.S. nuclear submarine. Specifically...
Today's CPUs operate at speeds measured in gigahertz rather than kilohertz. Is this statement true or false?
I have encountered the term "Kusabi" in two different contexts: once in the video game Fatal Frame II and again in the s...
Who are the Nomads in the Bandidos Motorcycle Club?
I have the chorus of a song stuck in my head, and I can't figure out who sings it or what the song is. I've tried search...
I just got hired for a part-time sales job at Home Depot, and I have my orientation tomorrow. I've never had a job where...
I’ve already checked the IKEA website, but they only provide instructions for the Brimnes bed with storage drawers. I sp...
What view in a presentation program allows you to display your slides in full-screen mode?