?
Solved

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

Posted on 2011-03-03
7
Medium Priority
?
641 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 2000 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 2000 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

762 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