7/25/2023 0 Comments Robocopy sync folders▪ /z: copy files in restartable mode which lets you resume a large transfer if it’s been interrupted. ▪ /e: copy subdirectories including empty directories. ▪ /s: copy subdirectories except empty directories. Here I’d like to list some helpful options: There are various options you can use with the robocopy command to meet different needs. The basic syntax of the robocopy command is as follows: It has been a built-in feature since Windows Vista and Windows Server 2008. Robocopy (Robust File Copy) is a command that is used to copy directories and files from one location to another. Easier way to perform two-way sync in Windows.How to use Robocopy to sync folders in two ways.Type CALL /? for a description of extensions to the CALL commandĪlso note that Using GOTO within parentheses - including FOR and IF commands - will break their context. Way to exit a batch script file without defining a label. GOTO command now accepts a target label of :EOF which transfersĬontrol to the end of the current batch script file. If Command Extensions are enabled GOTO changes as follows: That's why I use SETLOCAL EnableExtensions as a matter of general principle. Although Command Extensions are enabled by default, we can't presume in it. Note that if Command Extensions are disabled GOTO will no longer recognise the :EOF label (use exit /B instead of goto :EOF in the case). Set /P c=Sync TO or FROM Google Drive or BOTH or NOTHING ? Or something similar to next code snippet (keeping set /P user's interpelation): off Robocopy "C:\Users\Jake\Google Drive\\" ".\Google Drive\\" * /E /XO Robocopy ".\Google Drive\\" "C:\Users\Jake\Google Drive\\" * /E /XO Use /E instead of /MIR option and perform copy in both ways unattended: off E : Copy Subfolders, including Empty Subfolders. Than the source - don’t bother to overwrite it. XO : eXclude Older - if destination file exists and is the same date or newer PURGE : Delete destination files/folders that no longer exist in source. Maybe even without robocopy.Īs per ROBOCOPY /? (or ROBOCOPY.exe doc), /MIR option forces implicite /PURGE: /MIR : MIRror a directory tree - equivalent to /PURGE plus all subfolders (/E) Is there any way to fix this? I just need a two-way method of syncing both locations without the possibility of losing files/folders from one of them. So this causes the problem of files being lost forever if there's new content on both locations. sync FROM Google Drive, b.txt is copied to my flash drive from Google Drive but a.txt is gone from both. sync TO Google Drive, a.txt is copied to Google Drive from my flash drive but b.txt is gone from both. If I create "a.txt" on my flash drive and "b.txt" on Google Drive, and then if I: There's only one flaw however, and that's if each location has new content to sync. If I make a change on Google Drive, I type F which will sync changes from Google Drive. If I make a change on the flash drive, I run the batch file and type T which will sync my changes to Google Drive. Robocopy "C:\Users\Jake\Google Drive\ " ".\Google Drive\ " * /mir /xo Robocopy ".\Google Drive\ " "C:\Users\Jake\Google Drive\ " * /mir /xo This is what my code looks like right now: off This is so that regardless of which of the two locations I make or edit something, I can always sync the newest version onto both locations.īefore anything happens, the code also verifies that it's plugged into my computer and not someone else's by checking its name. Since robocopy is a one-way process, I set up my code so it asks you whether you want to either sync TO Google Drive or FROM Google Drive. So I've been trying to write a batch file which will sync my local Google Drive folder with my flash drive when I run it.
0 Comments
Leave a Reply. |