Computer Hope
Microsoft => Microsoft DOS => Topic started by: peer on December 17, 2010, 02:32:38 AM
-
one of my tasks is to update files in a folder that is on many computers. can I get help to make a batch file that runs on the client computer to check the contents of a folder by comparing it with the master folder that is in the "server computer". and if there are changes in the size of the file or there is a new file in the master folder, it will automatically be copied when the batch file is executed.
thanks a lot
-
that should be easy, but it gets more tricky if you would also need to delete files from the mirrors that are no longer on the original copy
-
that should be easy,
Tell us how then!!
-
one of my tasks is to update files in a folder that is on many computers. can I get help to make a batch file that runs on the client computer
It can be done in batch.
But may I ask why batch is the choice.
There are other methods often used.
-
Writing a batch file for this would border on the sadistic.
Written for XP, my personal favorite is SyncToy (http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx) which is *censored* near idiot proof. ;D
An alternative might be the RoboCopy GUI (http://www.softpedia.com/get/System/OS-Enhancements/RoboCopy-GUI.shtml). The GUI makes it easier than using the command line version which can be quite challenging.
Also try Google. A quick search turned up many scripts written in VBScript and Powershell.
Good luck. 8)
-
http://www.tech-pro.net/howto_033.html
"To use the batch file, open a command prompt and type SYNC followed by the paths of the two folders you want to synchronize, each in quotes. If you want to synchronize subfolders as well, add /S to the command line before pressing Enter. For example, suppose your project is kept in a folder called "My Project" on both your local PC and one with a network name of "DELL". To synchronize this folder, including any subfolders, type the command:
SYNC "C:\My Project" "\\DELL\My Project" /SWe recommend that you test this on something unimportant before trying it on valuable work files. Note that the two-line batch file has no "idiot-proofing", so it will happily try to synchronize entire hard disks if you tell it to! This method works, but it gets tiresome having to type in the paths of the two folders."
p.s. I did not test above method. Donald99
-
http://www.tech-pro.net/howto_033.html
"To use the batch file, open a command prompt and type SYNC followed by the paths of the two folders you want to synchronize, each in quotes. If you want to synchronize subfolders as well, add /S to the command line before pressing Enter. For example, suppose your project is kept in a folder called "My Project" on both your local PC and one with a network name of "DELL". To synchronize this folder, including any subfolders, type the command:
SYNC "C:\My Project" "\\DELL\My Project" /SWe recommend that you test this on something unimportant before trying it on valuable work files. Note that the two-line batch file has no "idiot-proofing", so it will happily try to synchronize entire hard disks if you tell it to! This method works, but it gets tiresome having to type in the paths of the two folders."
p.s. I did not test above method. Donald99
no, there is no such thing as a sync command
you ripped that out of it's context
they MADE a sync command that did this:
XCOPY "%1" "%2" /D /I %3
XCOPY "%2" "%1" /D /I %3
this is NOT wath he wants, this would put the same files on the master as on the client, only the client should get the same files of the master. the master should remain unaltered
a simple xcopy should do the trick, but it will only copy new files on the master to the client, and not delete files on the client that are no longer on the master
I had a similar problem on my external hdd but i managed to get around the problem
this batch file is run from my hdd (client)
small part of my solution:
title = making music backup...
xcopy /d /c /y "C:\Users\Polle\Music" "%~d0\Music" this copys all music files from my pc (master) to my hdd (client)
for /r "%~d0\Music\" %%F in (*.*) do echo %%F>> file.txt this lists all music files on my hdd (client) and puts them in a file called file.txt
for /F "tokens=2* delims=\" %%I in (file.txt) do if not exist "C:\Users\Polle\%%I\%%J" del "%~d0\%%I\%%J" takes each entry in file.txt and checks if it exists on my pc (master), if not, it deletes the file from the hdd
del file.txt delete the list of files
for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d" deletes all empty folders
this should do the trick, but it will need some adjusting if you want to use it
any of the gurus can improve this piece of code? I don't know that much of batch, but I managed to get around this problem this way, is there an easier or better way?
-
Good job.