-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
@echo off | ||
REM This program navigates to the specified directory and archives all files/folders | ||
REM Exception are "bin" and "obj" folders, as well as "Migrations" folder, hidden files and/or folders | ||
REM Archive is created at the source location | ||
|
||
REM Prompt User for Source Directory | ||
set /p sourcedir="Enter the full path of the source directory to copy: " | ||
|
||
REM Find the Name of the Last Folder in Source Directory | ||
set fullpath=%sourcedir% | ||
for %%F in ("%fullpath%\.") do set "foldername=%%~nxF" | ||
if "%foldername%"=="" ( | ||
for %%F in ("%fullpath%\..\.") do set "foldername=%%~nxF" | ||
) | ||
|
||
REM Set Archive Name to Last Folder Name Without .zip Extension | ||
set archivename=%foldername% | ||
|
||
REM Set Destination Path to Source Directory | ||
set destpath=%sourcedir% | ||
|
||
REM Set Destination Path to Desktop | ||
REM set destpath=%USERPROFILE%\Desktop | ||
|
||
REM Create a Temporary Directory for Exclusion file | ||
set tempdir=%temp%\%random% | ||
mkdir "%tempdir%" | ||
|
||
REM Create a Temporary Directory for Copy | ||
set tempdir_copy=%temp%\%random% | ||
mkdir "%tempdir_copy%" | ||
|
||
REM Create exclude.txt File in Temp Directory | ||
echo /hid> "%tempdir%\exclude.txt" | ||
echo bin\>> "%tempdir%\exclude.txt" | ||
echo obj\>> "%tempdir%\exclude.txt" | ||
echo .vs\>> "%tempdir%\exclude.txt" | ||
echo .zip>> "%tempdir%\exclude.txt" | ||
echo Migrations\>> "%tempdir%\exclude.txt" | ||
|
||
REM Copy Files From Source Directory to Temp Directory | ||
xcopy "%sourcedir%" "%tempdir_copy%" /EXCLUDE:%tempdir%\exclude.txt /Y /E | ||
|
||
REM If Older Archive Exists -> Delete | ||
if exist "%destpath%\%archivename%.zip" ( | ||
del /F "%destpath%\%archivename%.zip" | ||
) | ||
REM Create zip Archive at Specified Path (Integrated Windows ZipFile) | ||
powershell -command "Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::CreateFromDirectory('%tempdir_copy%', '%destpath%\%archivename%.zip', [System.IO.Compression.CompressionLevel]::Optimal, $false)" | ||
|
||
REM Create zip Archive at Specified Path (7-Zip) | ||
REM "C:\Program Files\7-Zip\7z.exe" a -tzip -mx9 -mfb258 -mpass=15 "%destpath%\%archivename%.zip" "%tempdir_copy%\*.*" | ||
|
||
REM Delete Temporary Directory for Copy | ||
rmdir /S /Q "%tempdir_copy%" | ||
|
||
REM Delete exclude.txt File | ||
del "%tempdir%\exclude.txt" | ||
|
||
REM Delete Temporary Directory for Exclusion file | ||
rmdir /S /Q "%tempdir%" | ||
|
||
REM Pause to See Output | ||
echo. | ||
@echo Archive is created and is located at %destpath%\%archivename%.zip | ||
pause |