-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZipForJudge.bat
90 lines (71 loc) · 2.97 KB
/
ZipForJudge.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@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 Ask User if they wish to keep Migrations or not?
set /p choice=Do you want to keep the "Migrations" folder? ([Y/Yes]/[N/No]):
set keepMigration=false
if /i "%choice%"=="Y" (
set keepMigration=true
) else (
if /i "%choice%"=="yes" (
set keepMigration=true
) else (
set keepMigration=false
)
)
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 Datasets\>> "%tempdir%\exclude.txt"
echo ExportResults\>> "%tempdir%\exclude.txt"
echo ImportResults\>> "%tempdir%\exclude.txt"
echo TestResults\>> "%tempdir%\exclude.txt"
REM If Choice is No Remove Migrations from .zip
if "%keepMigration%"=="false" (
echo Removing Migrations...
echo Migrations\>> "%tempdir%\exclude.txt"
)
REM Copy Files From Source Directory to Temp Directory
xcopy "%sourcedir%" "%tempdir_copy%" /EXCLUDE:%tempdir%\exclude.txt /Y /E /Q
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