Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

Child directories defined in script

Hey Experts.  I am using a script (which was authored by one of the superstars on EE) which copies files based on their file extension within two directories.  That function works flawlessly.  What I am looking at now is having the script look at those two directories and all sub-directories for the files to copy.

Such as:
Test (dir)
>Test\A
>Test\B
>>Test\B\1

I'm not sure how to define that in the script (see below).  Thank you in advance for your help.

 
@echo off
set DirList="D:\Test","D:\Test1"
set DestDir=d:\Home
set ExtList="doc","docx","pdf","vsd"
for %%A in (%DirList%) do (
 for %%B in (%ExtList%) do (
   copy "%%~A\*.%%~B" "%DestDir%"
 )
)

Open in new window

Avatar of Bill Prew
Bill Prew

For files in subfolders, do those just go into the same destination folder at the root level, without the original folder hierarchy?

~bp
If you just want a copy in the dest folder, then I think this should do that.

@echo off
set DirList="D:\Test","D:\Test1"
set DestDir=d:\Home
set ExtList="*.doc","*.docx","*.pdf","*.vsd"
for %%A in (%DirList%) do (
 for /R "%%~A" %%B in (%ExtList%) do (
   copy "%%~B" "%DestDir%"
 )
)

Open in new window

~bp
Avatar of samiam41

ASKER

@bp, you are exactly right.  What appears to be happening is that the script isn't pulling the files from the second directory listed.  
Copying files from "test" but not "test1".  High probability that is in relation to the user (me) running the script.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Insane.  Sick.  Perfect.

Thanks billprew.  Simply amazing!
Thanks, you're too kind.

~bp