-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdelete_operational_memory.bat
More file actions
64 lines (55 loc) · 1.4 KB
/
Copy pathdelete_operational_memory.bat
File metadata and controls
64 lines (55 loc) · 1.4 KB
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
@echo off
setlocal EnableExtensions EnableDelayedExpansion
rem Deletes every operational_memory.json file under the configured memories folder.
cd /d "%~dp0"
set "MEMORIES_ROOT=%CD%\memories"
set "TARGET_NAME=operational_memory.json"
set "DRY_RUN=0"
:parse_args
if "%~1"=="" goto args_parsed
if /I "%~1"=="--root" (
if "%~2"=="" (
echo [ERROR] --root requires a directory path.
exit /b 2
)
set "MEMORIES_ROOT=%~2"
shift
shift
goto parse_args
)
if /I "%~1"=="--dry-run" set "DRY_RUN=1"
if /I "%~1"=="/dry-run" set "DRY_RUN=1"
shift
goto parse_args
:args_parsed
if not exist "%MEMORIES_ROOT%\" (
echo [ERROR] memories folder does not exist: "%MEMORIES_ROOT%"
exit /b 2
)
set /a MATCHED=0
set /a DELETED=0
set /a FAILED=0
for /R "%MEMORIES_ROOT%" %%F in (%TARGET_NAME%) do (
if exist "%%F" (
set /a MATCHED+=1
if "!DRY_RUN!"=="1" (
echo [DRY-RUN] Would delete: %%F
) else (
echo Deleting: %%F
del /F /Q "%%F"
if errorlevel 1 (
set /a FAILED+=1
echo [ERROR] Failed to delete: %%F
) else (
set /a DELETED+=1
)
)
)
)
if "%DRY_RUN%"=="1" (
echo Dry run complete. Matched !MATCHED! files.
exit /b 0
)
echo Deleted !DELETED! files. Failed !FAILED! files. Matched !MATCHED! files.
if !FAILED! GTR 0 exit /b 1
exit /b 0