Solved

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

Posted on 2011-03-03
7
612 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
ID: 35029237
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
ID: 35036951
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
ID: 35037062
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:NancyCPS
ID: 35037619
Thanks!!!

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

Expert Comment

by:knightEknight
ID: 35037631
/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
ID: 35037643
Ahhh great!  Thanks so much.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35037822
Glad to help where I can.  :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

896 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