Help needed for batch directory processing

September 4, 2011 at 23:41:17
Specs: Windows 7, 2 GB
I have a fair amount of experience with cmd batch scripts, but this one has me stumped. I want to copy one directory tree to another directory tree, processing each file copied with a command.

The recursive FOR loop calls the command for each file, with the new file created as output. For example:

for %%D in (C:\source\*) do command %%D >> C:\destination\%%~nD.mod

However, this needs to be done for the entire directory tree under source. When complete, the two directory trees should be identical. The structure is many subdirectories deep, and can change. I can't simply throw in the /R switch, because I need the rest of the relative path for each output file.

There are three rules:
1) It needs to run under stock Win7, WinXP, and Win2K.
2) The source directory cannot be modified by the script, as no write permissions may be available.
3) Source cannot be copied in full and then modified. Storage may not be big enough for two unprocessed copies. I plan to xcopy (/t) the directory structure first.

I don't know how to get batch files to play nicely with relative directories (like Linux). Any help to solve this is appreciated. Thanks!


See More: Help needed for batch directory processing

Report •


#1
September 5, 2011 at 14:33:13
I don't know how to get batch files to play nicely with relative directories (like Linux).
Oh, it's pretty much exactly like Linux. Only you have drive letters, so some things are easier, and some things are harder. You just don't have nearly the amount of tools.

How To Ask Questions The Smart Way


Report •

#2
September 10, 2011 at 07:58:36
I'm bored, so I might as well revisit old threads. In this scenario it's easier to play with drive letters and use full paths rather than mucking about with relative paths:

Untested:

subst i: c:\source
for /r i:\ %%a in (*) do command %%a >> c:\destination\%%~PNXa
subst i: /d

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question