-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.bat
72 lines (64 loc) · 1.29 KB
/
example.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
@echo off
setlocal enableDelayedExpansion
set d=%~dp0
set "options=-dir:"%CD%" -keep:15 -pattern:"" -help: -?: -d: -debug:"
call %d%\options.bat %*
if !-help!==1 (
set -?=1
) else (
if !-?!==1 (
set -help=1
)
)
if "!-pattern!"=="" (
set -pattern="*"
)
if !-debug!==1 (
set -d=1
echo -debug = !-debug!
call:debug
) else (
if !-d!==1 (
set -debug=1
echo -debug = !-debug!
call:debug
)
)
if !-help!==1 (
call:help %0
endlocal
exit /b 0
)
if !-debug!==1 (
for /f "skip=%-keep% eol=: delims=" %%F in ('dir /b /o-d !-dir!\!-pattern!') do echo "!-dir!\%%F"
pause
) else (
for /f "skip=%-keep% eol=: delims=" %%F in ('dir /b /o-d !-dir!\!-pattern!') do @del "!-dir!\%%F"
)
endlocal
exit /b 0
:help
echo.
echo Usage of:
echo %~n0 [Flags] [Options]
echo.
echo Flags:
echo -help / -? prints usage
echo -debug / -d prints extra information
echo.
echo Options:
echo -dir folder from where to delete files [default is \%CD\%]
echo -keep number of files to keep [default is 9]
echo -pattern pattern to apply [default is '*']
echo.
exit /b 0
:debug
echo.
echo Option Values:
echo -dir = !-dir!
echo -keep = !-keep!
echo -pattern = !-pattern!
echo -help = !-help!
echo -debug = !-debug!
echo.
exit /b 0