views:

69

answers:

4

Hello,

I need help writing a batch file to update templates on a database. Basically, all our clients have their own folder, with multiple templates inside. Due to the computer illiteracy of my office (sigh), there's no real better way to fix this. However, I need a way to update those templates in a batch. For instance

\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD

is updated. I then need to copy it to:

\\SERVER\Client Files\Client 1\Correspondence;
\\SERVER\Client Files\Client 2\Correspondence;

...etc. Essentially, I need to copy to \\SERVER\Client Files\\*\\, and I need to make it a batch file that I can train someone else to use whenever I leave this job. How can I do that?

Thanks.

A: 

The new versions of Windows (7 and 2008 Server R2) have the robust file copy tool (robocopy). This can be installed on XP and 2003 also be installed using the Resource Kit. Essentially, robocopy gives you a command-line directory mirroring tool that could help you accomplish what you're trying to do. Simply place robocopy commands into a batch file (/MIR = mirror directory contents /XJ = ignore junctions) :

robocopy <source_dir> <destination_dir> /MIR /XJ
Kit Roed
A: 

You didn't indicate which operating system you are working under. Let me guess its windows. My DOS BAT file knowledge is limited, but you could try creating a BAT file with something like:

set Src="\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD"
set DestA="\\SERVER\Client Files\
set DestB=\Correspondence;"
FOR /F "delims=" %%i IN (distribution.txt) DO copy %Src% %DestA%%%i%DestB%

and then create a distribution.txt file like:

Client 1
Client 2

Running this BAT file will read the distribution.txt file and issue a copy command for each line in it. As follows:

COPY "\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD" "\\SERVER\Client Files\Client 1\Correspondence;"
COPY "\\SERVER\New Client Template Folder\Correspondence\Transmittal Letter.WPD" "\\SERVER\Client Files\Client 2\Correspondence;"

But there must be a better way!!!!

You can get more help on the FOR command by typing help for at the DOS prompt.

If you don't like the idea of having to build/maintain the distribution.txt file, you could play with using DIR /A:D /B "\\SERVER\Client Files\*" to drop a directory listing into a temporary file, then use it as input to the FOR loop.

NealB
A: 

Uh oh, since I didn't have an account and am now on a different PC (home, not work), I can't edit my original question.

Kit Roed, robocopy will allow me to selectively overwrite only the old templates in the client files with the new templates contained in my templates folder and subfolders? How do I format the destination directory to copy into not just one client folder, but all of them? It is a dynamically growing list that I do not have the time to manually edit.

I am using Windows XP.

[EDIT: Testing this at home on my Win 7 machine and a dummy series of folders, I'm getting an "ERROR: INVALID PARAMETER #2" message whenever I try to copy to a destination directory like C:\Test\Open_Client_Files\*\, which is what I really need to be able to do, unless there's an automated way to generate a folder list and incorporate it dynamically. My friend suggested

That's where the Cygwin commands would come in. Something like "foreach $path in 'ls | grep "template.abc" ' robocopy //newtemps/template.abc $path "

Aaron
A: 

the Replace command might help.

Andy Morris