The main reason you may want to sync folders on a single machine is to backup your data. You would probably be best to find a backup utility to do this.
If you want to sync folders over networked drives, this guide may help you also. There are more detailed articles at Inspect My Gadget on syncing documents between two networked computers. Find them here.
On the very odd occasion you do want to sync folders on a single computer, it is not too hard to achieve. There are number of applications available to help you do this, but many of them cost money. Windows has a solution by a command in the command prompt which will work on all Windows PC’s. Microsoft also offers a program called SyncToy which does the same thing with a nice GUI interface.
This is a two part article. Part 1 will look at using xcopy to sync your folders, and Part 2 will look at using SyncToy.
Part 1 will cover the following topics.
- How to use xcopy
- How to put xcopy into a batch file
- How to schedule the batch file to run a sync at a set time.
The reason I like xcopy is that it is quick to setup, and you do not require any additional software to get it to work. This means it is good for 1 off syncs. SyncToy will be the best solution for most people who require to sync more frequently.
This two part article was originally going to be much shorter, but I got typing and my fingers wouldn’t shut up. I recommend that beginners read the entire article to prevent disaster and to get all the extra information. Advanced users will probably be able to skim through most of it, wary that a typing error may result in lost data.
I am generally a big fan of off-line files for smaller syncs over networked drives. This does not work with two folder on a single computer, so we have to look at other methods. The advantage of off-line files is that the data on both computers, while the computers are connected, will be the same even if a sync has not taken place recently.
With the methods in this article, the folders will only be the same after a sync which you have scheduled to run, or by running the sync manually. I am not aware of any applications which will recognise changes as they are made and force a sync at that time.
It is very important before you play with this, that you backup your data as you may need to do a little tweaking to get it working right for you. You may overwrite files with wrong versions if you make a typo. This is particularly important with xcopy. The easiest way to backup your data is to use Windows File Explorer to copy your files to a safe place. I can’t be held responsible for lost data. Do this at your own risk.
A bit of information about XCOPY:
Xcopy is an MS-DOS command which expands on the normal copy command, giving you a thorough list of switches to help you get it to work just as you want. The advantages of the xcopy command over the copy command is that it lets you copy only updated files, by a entering a series of switches. The copy command will copy the whole directory and prompt you if files need to be overwritten.
For most backup purposes, you only need to go one way. One of your folders will be a work folder(source) and another will be the backup folder(destination). As new files will not be created in the backup folder, you do not have to sync the backup folder back to the source folder. If you do need to Sync both ways, just run the command twice, switching the source and destination folders the second time. This will be covered further in this article.
Play with XCOPY:
The best place to start is to open up a command prompt by clicking on “Start”, selecting “Run”, and typing in “cmd” followed by enter. If you are using Vista, you can type “cmd” directly into the search box followed by enter. Either way, you should end up with a command prompt.
type “xcopy /?” followed by enter
This will show you all of the switches you can play around with. I will be using the /D and /E switches only in this article. You can feel free to play with the others, though I have not needed them myself. Just take caution, this is where you can stuff up your data if you have not backed up.
The /D switch copies all the files from your source to your destination, unless a file at your destination is newer than the source. If there is a newer file at the destination, that file will be skipped and the next file will be checked. The copying of a file will only take place if the destination file does not yet exist or is older than the source.
The /E switch tells xcopy to include folders and subfolders. If you do not include this, only the files in the root of the folder will be copied. Worth noting is /S which will copy all folders across apart from empty folders. /S can be used instead of /E
There will NOT be any prompts asking you if you want to overwrite files using only the /D switch. Xcopy will overwrite the file in the destination if the source file is newer. There is no easy way to recover the file in XP or Vista. If you are a Vista user, you may get lucky by using the “Previous Version” functions in folders properties.
Sync with XCOPY:
The command “xcopy folder1 folder2 /D /E” will copy all the folders and files from folder1 to folder2. If a file exists in folder 2 that is newer or the same as a file in folder 1, the file will not be overwritten.
So to do it both ways, you can do as above and then the command “xcopy folder2 folder1 /D /E”. This will copy any folders and files that are new or don’t exist in folder1 across to folder1.
Both folders will now be the same.
Setting up a batch file:
You can place batch files anywhere on your computer, but for once I will recommend putting it in the root of your C: drive. If you want to create multiple files, create a folder called “sync” or “batch” to keep it tidy.
Open up Notepad, it’s in you accessories folder in the start menu.
You don’t need to make the batch file very complicated. If you have multiple syncs, you can put them all in the once batch file.
Start small with some test folders to be safe. Please don’t start off syncing your photos or music on your first run.
Put in the following commands, on separate lines, replacing folder 1 & 2 for your own folder and path names.
xcopy C:\folder1 C:\folder2 /D /E
xcopy C:\folder2 C:\folder1 /D /E
Save your file as sync.bat. You will need ensure you don’t save it as a txt file by selecting all files in the filetype dropdown.
You can test this out now, by double clicking on the batch file. You should then be able to prove it has worked by both folders containing the same files.
Test it some more by putting a text file in folder and then syncing. Check that the file is copied across to both. Try updating both text files and then syncing your folders. The most recently updated text file should be able to be found on both, with the older of the two being lost forever.
Scheduling your batch file:
It is nice to think that we will backup our data regularly on our own accord, but if you are like the other 4 billion or so computer users in this world, you would find it best to schedule it so you don’t need to check up on it again.
This is slightly different between XP and Vista, but the theory is the same so I will run through how to do this in XP. Vista calls their scheduler “Task Scheduler”, where as XP calls its scheduler “Scheduled Tasks”. Both can be found by clicking “Start” -> “Accessories” -> “System Tools”.
Click “Add Scheduled Task”
Click “Browse” and navigate to your batch file
Select how frequently you would like it to happen. If your computer is on all the time, 3am is ideal. If you don’t have your computer on much, make it happen as your computer starts. This is completely up to you.
Follow the date prompts and that is it.
You are still able to launch the file manually if you require it to happen instantly, but otherwise, your folders will always be synced at the scheduled time.
Please check out part two of this article when it is available (Monday), which covers SyncToy so you can compare the two methods and figure out which you would prefer to use. I hadn’t played with xcopy much before writing this article, and I am thinking I may well end up using it over SyncToy. I feel like there is more control this way.
I hope you have enjoyed this article and found it useful. Please stick around and check out some other articles at Inspect My Gadget.