Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::@echo off
- color f0
- setlocal enabledelayedexpansion
- goto begin
- :stringLength ::string
- set tempstring=%1
- set /a stringLen=0
- call:stringLengthLoop %tempstring%
- goto:eof
- :stringLengthLoop
- if defined tempstring (
- set tempstring=%tempstring:~1%
- set /a stringLen += 1
- goto stringLengthLoop
- )
- goto:eof
- :analyzeTime ::time
- set lastMod=%1
- set year=%lastMod:~0,4%
- set month=%lastMod:~5,2%
- set day=%lastMod:~8,2%
- set hour=%lastMod:~11,2%
- set minute=%lastMod:~14,2%
- goto:eof
- :compareModifiedDate ::file1 file2
- echo Comparing files
- for %%i in (%1) do (set time1=%%~ti)
- for %%i in (%2) do (set time2=%%~ti)
- call:analyzeTime %time1%
- set /a year1=%year%
- set /a month1=%month%
- set /a day1=%day%
- set /a hour1=%hour%
- set /a minute1=%minute%
- call:analyzeTime %time2%
- set /a year2=%year%
- set /a month2=%month%
- set /a day2=%day%
- set /a hour2=%hour%
- set /a minute2=%minute%
- if %year1% EQU %year2% (
- if %month1% EQU %month2% (
- if %day1% EQU %day2% (
- if %hour1% EQU %hour2% (
- if %minute1% EQU %minute2% (
- set recent=none
- ) else if %minute1% GTR %minute2% (
- set recent=file1
- ) else (
- set recent=file2
- )
- ) else if %hour1% GTR %hour2% (
- set recent=file1
- ) else (
- set recent=file2
- )
- ) else if %day1% GTR %day2% (
- set recent=file1
- ) else (
- set recent=file2
- )
- ) else if %month1% GTR %month2% (
- set recent=file1
- ) else (
- set recent=file2
- )
- ) else if %year1% GTR %year2% (
- set recent=file1
- ) else (
- set recent=file2
- )
- goto:eof
- :begin
- if exist "%homedrive%%homepath%\Drive" (
- set drivePath=%homedrive%%homepath%\Drive
- goto deviceSetup) else (
- goto customDrivePath)
- :customDrivePath
- set /p drivePath=Google Drive folder was not found. Specify its path:
- if exist %drivePath% (goto sync) else (goto customPath)
- :deviceSetup
- set /p devicePath=Which folder path would you like to sync?
- if exist %devicePath% (goto syncDrivetoDevice) else (goto deviceSetup)
- :syncDrivetoDevice
- call:stringLength %drivePath%
- set /a driveLength=%stringLen%
- call:stringLength %devicePath%
- set /a deviceLength=%stringLen%
- for /d /r %drivePath% %%d in (*) do (
- set currentDriveFolderPath=%%d
- if not exist "%devicePath%!currentDriveFolderPath:~%driveLength%!" (
- mkdir "%devicePath%!currentDriveFolderPath:~%driveLength%!"
- )
- for %%f in (*.*) do (
- set currentFile=%%f
- if exist "%devicePath%!currentDriveFolderPath:~%driveLength%!!currentFile!" (
- set currentDriveFile="!currentDriveFolderPath!\!currentFile!"
- set currentDeviceFile="%devicePath%!currentDriveFolderPath:~%driveLength%!!currentFile!"
- call:compareModifiedDate !currentDriveFile! !currentDeviceFile!
- if !recent! == file1 (
- copy /y !currentDriveFile! !currentDeviceFile!
- ) else if !recent! == file2 (
- copy /y !currentDeviceFile! !currentDriveFile!
- )
- ) else (
- set source
- copy /y !currentDriveFile! !currentDeviceFile!
- )
- )
- )
- :syncDevicetoDrive
- for /d /r %devicePath% %%d in (*) do (
- set currentDeviceFolderPath=%%d
- if not exist %drivePath%!currentDeviceFolderPath:~%deviceLength%! (
- mkdir "%drivePath%!currentDeviceFolderPath:~%deviceLength%!"
- for %%f in (*.*) do (
- set currentFile=%%f
- if not exist "%drivePath%!currentDeviceFolderPath:~%DeviceLength%!!currentFile!" (
- copy /y !currentDriveFile! !currentDeviceFile!
- )
- )
- )
- )
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement