Skip to content

Instantly share code, notes, and snippets.

@simongcc
Created September 22, 2016 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simongcc/d62cfbd8eba72d73a04ea6d18afbe3db to your computer and use it in GitHub Desktop.
Save simongcc/d62cfbd8eba72d73a04ea6d18afbe3db to your computer and use it in GitHub Desktop.
@echo off
rem Automatically name with timestamp by drag and drop folder or file into this batch file
rem originally refer to some online tutorials, will add back if I find it
rem get local date time
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
rem set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2% %ldt:~8,2%:%ldt:~10,2%:%ldt:~12,6%
set ldt=%ldt:~0,4%%ldt:~4,2%%ldt:~6,2%-%ldt:~8,2%%ldt:~10,2%%ldt:~12,2%
set destination=C:\_Public-Share\_Project_Bak
set destination2=Z:\_Project_Bak
set zip_exe="C:\Program Files\7-Zip"
set config_file="C:\Users\simon.ng\desktop"
set dropbox_bak="C:\Users\simon.ng\Dropbox\_work\_projects\_bak"
rem get the drag N drop filename and zip
set "arg=%*"
set "arg=%arg:)=^)%"
set "arg=%arg:(=^(%"
rem for %%a in (%arg%) do echo %%~fa
rem zip multiple folder by dragging to this batch file
echo %arg%
echo %destination%
echo %zip_exe%
rem for %%a in (%arg%) do echo "%destination%\%%~na-%ldt%.zip" "%%~na"
for %%a in (%arg%) do %zip_exe%\7z.exe a -tzip "%destination%\%%~na-%ldt%.zip" "%%~na" -xr@"%config_file%\archive_exclude.txt"
rem echo for %%a in (%arg%) do xcopy "%destination%\%%~na-%ldt%.zip" "%dropbox_bak%" /Y
rem for %%a in (%arg%) do xcopy "%destination%\%%~na-%ldt%.zip" "%dropbox_bak%" /Y
for %%a in (%arg%) do xcopy "%destination%\%%~na-%ldt%.zip" "%destination2%" /Y
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment