Solved

recursive copy

Posted on 2003-11-12
7
17,841 Views
Last Modified: 2012-06-21
Have a question regarding a dos batch copy.  Say I have the following dir structure - a1\archive\a.txt, b1\archive\b.txt, ... , z1\archive\z.txt.  How can I write a batch that will essentially go through the list of directories, and copy the *.txt file one directory level up.  ie, copy a.txt from archive sub dir to a1\, copy b.txt from archive to \b1, etc...

Thanks.
0
Comment
Question by:pscuenco
7 Comments
 

Expert Comment

by:adbabypenguin
Comment Utility
If your directory structure was really like that, you could use this:

You would type in: rcopy.bat a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 etc... z1

The batch file would contain:
@echo off
cd %1
copy archive\%1.txt ..
cd ..
cd %2
copy archive\%2.txt ..
cd ..
cd %3
copy archive\%3.txt ..
cd ..
cd %4
copy archive\%4.txt ..
cd ..
cd %5
copy archive\%5.txt ..
cd ..

etc...etc...etc...

cd %26
copy archive\%26.txt ..
cd ..
echo Done

The effect would be:

\---a1---archive---a1.txt
  |
  |--a2---archive---a2.txt

etc...

to

\---a1---a1.txt
  |
  |--a2---a2.txt

etc...
0
 
LVL 16

Expert Comment

by:_nn_
Comment Utility
I'm afraid %26 will be interpreted as '%2' and '6' ...

Based on your requirements, I would try :

@echo off
for %%k in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do copy %%k1\archive\%%k.txt %%k1\%%k.txt
0
 

Expert Comment

by:adbabypenguin
Comment Utility
I tried to figure out a for statement, but ended up not being able to. But that for statement should work.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:lincoln_stern
Comment Utility
Xcopy /s will do subdirectories
0
 

Accepted Solution

by:
PashaMod earned 0 total points
Comment Utility
PAQed - no points refunded (of 250)

PashaMod
Community Support Moderator
0
 
LVL 1

Expert Comment

by:lesgetdown
Comment Utility
Just for reference this works
copy into a text file and rename <filename>.bat or .cmd if u like
Set the output directory to the directory that you want to output:


set outputdir=c:\test
if NOT exist %outputdir% mkdir %outputdir%
if exist copylist.txt rm copylist.txt

xcopy /S/L *.txt %outputdir% > copylist.txt
for /f "tokens=*" %%a in (copylist.txt) do copy %%a %outputdir%
rm copylist.txt
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now