Solved

Copy commands work in command prompt but not in BAT or CMD file

Posted on 2011-03-03
7
602 Views
Last Modified: 2012-05-11
When I use the following lines from a command prompt to copy files from subfolders into one folder it works just fine.  However, when I enter them into a BAT or CMD file, they no longer work.  What am I missing?

E:\vol2\folder1\myfolder
for /f "tokens=*" %a in ('dir /b /s /a-d') do @copy "%a" "P:\folder1\myfolder2\234567" /y
0
Comment
Question by:NancyCPS
  • 4
  • 3
7 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
Comment Utility
In .bat and .cmd files, you need to double the percent symbols:

for /f "tokens=*" %%a in ('dir /b /s /a-d') do @copy "%%a" "P:\folder1\myfolder2\234567" /y
0
 
LVL 1

Author Comment

by:NancyCPS
Comment Utility
Now the batch file is working - however, it copies the entire drive (E:\)  instead of copying the folders that I want (E:\vol2\folder1\myfolder).  Imagine my surprise when I had over 4000 files instead of 400.
0
 
LVL 33

Assisted Solution

by:knightEknight
knightEknight earned 500 total points
Comment Utility
That's because in the first line you have this:

  E:\vol2\folder1\myfolder

but I think you meant to have this:

  CD/d  E:\vol2\folder1\myfolder
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:NancyCPS
Comment Utility
Thanks!!!

what is the /d switch after CD?
0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
/d changes the drive as well as the current directory.  It is the same as doing this:

E:
CD  E:\vol2\folder1\myfolder
0
 
LVL 1

Author Comment

by:NancyCPS
Comment Utility
Ahhh great!  Thanks so much.
0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
Glad to help where I can.  :)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now