Select a Category

How to automate moving files to local Google Drive?

Background

Google automatically synchronizes files in the Google Drive directory on local computer with the cloud. However, any files not in the Google Drive folder is not backup. A network drive is used to store files such as photo folders from different users. Spaces are used in folder name, such as “G:\Pictures\2003-03 Trip to Disney World”. New file folders are added to G drive.  With the recent revelation of ICloud photo leak, all folders should be password protected before moving to Google Drive.

Solution

Use 7Zip, an open source compression software on file server to package folders with password. Use one zip file per folder. If there is space in the zipped file, replace space with “_” to make them easier to handle.

Below is the batch to package folder, replace space in zip file name with “_” and move the zip files to Google Drive’s backup directory.

REM Use 7zip to password backup folder and put them in destination folder
REM Use for loop to loop through all folders
for /d %%X in (G:\Pictures\*) do (
“c:\Program Files\7-Zip\7z.exe” a -pPassword “%%X.zip” “%%X\”
call :rename_file “%%X” “.zip”
)
:rename_file
::if file name contains space, replace splace with _. Move end file to Google Drive backup directory
set name=%~1
set extension=%~2
set file=%name%%extension%
set newName=%file: =_%
if not x”%file: =M%”==x”%file%” (        ::echo It contains space
echo contains space, copy file to new name and delete existing file
copy “%file%” %newName%
del “%file%”
) else (
echo not space in file name “%file%”, next file
)
echo moving…%newName%
move /Y %newName% I:\GoogleDrive”\Google Drive Backup”\

References

  1. IF statement in batch file: www.robvanderwoude.com/if.php
  2. Call statement in batch file: jpsoft.com/help/call.htm
  3. DOS – String Manipulation: www.dostips.com/DtTipsStringManipulation.php
  4. SET statement in batch file: ss64.com/nt/set.html

Comments are closed.