Skip to main content
A

Anonymous

Nov 24, 2024

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

A
Anonymous

Feb 06, 2025

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…

A
Anonymous

Dec 27, 2024

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.

Want to answer this question?

Join our community to share your knowledge!

Related Questions

3
A question for bike riders, How come the back wheel is always following the front one, Is that odd or what. ?

Have you ever noticed how the rear wheel of a bike seems to follow the front wheel closely? Why does this happen, and is...

8
CSS stands for Cybernet Slash Support or Cybernet Software Systems ?

What does CSS stand for: Cybernet Slash Support or Cybernet Software Systems? I came across a company located in T. Naga...

10
On a U.S. Nuclear submarine, is the Xo higher ranked than the Captain?

I was watching the movie "Crimson Tide" and became curious about the ranks within a U.S. nuclear submarine. Specifically...

1
Today’s CPUs run at speeds measured in kilohertz.?

Today's CPUs operate at speeds measured in gigahertz rather than kilohertz. Is this statement true or false?

2
What does the word ‘Kusabi’ mean?

I have encountered the term "Kusabi" in two different contexts: once in the video game Fatal Frame II and again in the s...

6
What is a Bandidos Nomad?

Who are the Nomads in the Bandidos Motorcycle Club?

6
What is the song with lyrics “do you wanna ride in the back seat of a caddy”?

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...

4
What should I wear for Home Depot orientation tomorrow?

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...

4
Where can I find the instructions for the Ikea Brimnes bed?

I’ve already checked the IKEA website, but they only provide instructions for the Brimnes bed with storage drawers. I sp...

7
Which view in a presentation program displays your slides in full-screen mode?

What view in a presentation program allows you to display your slides in full-screen mode?