Solved

recursive copy

Posted on 2003-11-12
7
17,848 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
[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
7 Comments
 

Expert Comment

by:adbabypenguin
ID: 9736083
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_
ID: 9738953
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
ID: 9744195
I tried to figure out a for statement, but ended up not being able to. But that for statement should work.
0
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 

Expert Comment

by:lincoln_stern
ID: 9822908
Xcopy /s will do subdirectories
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 10088899
PAQed - no points refunded (of 250)

PashaMod
Community Support Moderator
0
 
LVL 1

Expert Comment

by:lesgetdown
ID: 20818954
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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