开发者

How do I use a batch copy to update files?

开发者 https://www.devze.com 2022-12-22 23:11 出处:网络
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),

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 bat开发者_如何学Cch file that I can train someone else to use whenever I leave this job. How can I do that?

Thanks.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消