Skip to content

Instantly share code, notes, and snippets.

@tcaddy
Last active May 23, 2017 15:19
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 tcaddy/e5642df609272383d7d9dfb317bfacb7 to your computer and use it in GitHub Desktop.
Save tcaddy/e5642df609272383d7d9dfb317bfacb7 to your computer and use it in GitHub Desktop.
BAT file to copy files and make a ZIP archive
@ECHO OFF
SET CURRENTDIR="%cd%"
SET DIRTOZIP="%TEMP%\_A%time::=.%"
MKDIR %DIRTOZIP%
CD %DIRTOZIP%
COPY /B /V /Z "source" "destination"
set FILETOZIP="%DIRTOZIP%\*"
set TEMPDIR="%TEMP%\_B%time::=.%"
rmdir %TEMPDIR%
mkdir %TEMPDIR%
copy %FILETOZIP% %TEMPDIR%
echo Set objArgs = WScript.Arguments > _zipIt.vbs
echo InputFolder = objArgs(0) >> _zipIt.vbs
echo ZipFile = objArgs(1) >> _zipIt.vbs
echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
echo wScript.Sleep 2000 >> _zipIt.vbs
CScript _zipIt.vbs %TEMPDIR% "%CURRENTDIR%\zipped_files.zip"
DEL _zipIt.vbs
RMDIR %DIRTOZIP%
CD %CURRENTDIR%
ECHO ZIP file has been saved: zipped_files.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment