[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

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

0
samiam41
Asked:
samiam41
  • 4
  • 3
1 Solution
 
Bill PrewCommented:
For files in subfolders, do those just go into the same destination folder at the root level, without the original folder hierarchy?

~bp
0
 
Bill PrewCommented:
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
0
 
samiam41Author Commented:
@bp, you are exactly right.  What appears to be happening is that the script isn't pulling the files from the second directory listed.  
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
samiam41Author Commented:
Copying files from "test" but not "test1".  High probability that is in relation to the user (me) running the script.
0
 
Bill PrewCommented:
Okay, I think this is a peculiarity with the FOR /R, give this a try.

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

:DoDir [dirname]
  for /R "%~1" %%B in (%ExtList%) do (
    copy "%%~B" "%DestDir%"
  )
  exit /b

Open in new window


~bp
0
 
samiam41Author Commented:
Insane.  Sick.  Perfect.

Thanks billprew.  Simply amazing!
0
 
Bill PrewCommented:
Thanks, you're too kind.

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now