Reputation: 73
I would like to make an automated task by using a .bat file in order to copy some files from the server to users' computers. The destination of the files can be on different partitions but the location (folder-wise) is the same.
For example I have 1 file I want to copy from the server to C:\Program Files\Program
or D:\Program Files\Program
(note that the path, apart from the partition is the same)
Upvotes: 0
Views: 453
Reputation: 41224
This will copy a few files:
copy "\\server\share\*.txt" "%ProgramFiles%\target folder\"
This will copy a folder tree:
xcopy "\\server\share\folder\*.*" "%ProgramFiles%\target folder\" /s/h/e/k/f/c/z
The %ProgramFiles%
variable holds the location of the installations program files folder.
Upvotes: 1
Reputation: 7095
Something like this should work if you're running it from the server with admin rights.
@echo off
setlocal
for %%a in (computer1 computer2 computer3) do (
for %%b in (c d) do (
if exist "\\%%a\%%b$\Program Files\Program\." (
xcopy /F /I "yourfile.ext" "\\%%a\%%b$\Program Files\Program"
)
)
)
If you're running it from a workstation, you could do something like this:
@echo off
setlocal
for %%a in (c d) do (
if exist "%%a:\Program Files\Program\." (
xcopy /F /I "\\Server\Share\yourfile.ext" "%%a:\Program Files\Program"
)
)
Upvotes: 1
Reputation: 9776
Do you mean a basic copy from one dir to another like this.
For a file
@echo off
echo copying files
copy /Y C:\Program Files\Program\TheFileYouWantToCopy.file D:\Program Files\Program\TheFileYouWantToCopy.file
echo copying files done.
pause
goto :eof
Replace "TheFileYouWantToCopy.file" with as it says the file you want to copy.
For a dir
If you want to copy a dir from one place to another use this:
@Echo Off
Echo Please Press "d"
xcopy "C:\Program Files\Program" "D:\Program Files\Program"
Echo done
pause
goto :eof
In response to comments:
Try %SystemDrive%\Program Files\Program as your path. %SystemDrive% is just where the system stores its files and that can be anything from A:/ to Z:/.
Upvotes: 0