Add dry run mode and auto root path via %~dp0
This commit is contained in:
@@ -42,12 +42,32 @@ ROOT\
|
|||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
1. Open `Rename and Move PT STMT.bat` in Notepad
|
1. Place `Rename and Move PT STMT.bat` in the root patient folder
|
||||||
2. Set the `ROOT` variable to your actual folder path:
|
2. Double-click to run — it automatically uses the folder it lives in as the root
|
||||||
```bat
|
|
||||||
set "ROOT=C:\Users\Melissa\Documents\Patients"
|
### Dry Run
|
||||||
```
|
|
||||||
3. Save and double-click to run
|
The script defaults to **dry run mode** — it will print every action it would take without touching any files. To run for real, open the file in Notepad and change:
|
||||||
|
|
||||||
|
```bat
|
||||||
|
set "DRYRUN=1"
|
||||||
|
```
|
||||||
|
to:
|
||||||
|
```bat
|
||||||
|
set "DRYRUN=0"
|
||||||
|
```
|
||||||
|
|
||||||
|
Dry run output looks like:
|
||||||
|
```
|
||||||
|
[DRY RUN] No files will be changed.
|
||||||
|
|
||||||
|
Found: C:\Patients\abc\Patient\Export\.
|
||||||
|
RENAME export.txt > PT STMT_20260423.txt
|
||||||
|
MKDIR PT STMT_20260423
|
||||||
|
MOVE PT STMT_20260423.txt > PT STMT_20260423\
|
||||||
|
MOVE 1000001.tif > PT STMT_20260423\
|
||||||
|
MOVE 1000002.tif > PT STMT_20260423\
|
||||||
|
```
|
||||||
|
|
||||||
### Notes
|
### Notes
|
||||||
|
|
||||||
|
|||||||
+21
-12
@@ -1,8 +1,11 @@
|
|||||||
@echo off
|
@echo off
|
||||||
setlocal enabledelayedexpansion
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
REM === SET YOUR ROOT FOLDER HERE ===
|
REM === SET TO 1 TO PREVIEW WITHOUT MAKING CHANGES, 0 TO RUN FOR REAL ===
|
||||||
set "ROOT=C:\path\to\patient"
|
set "DRYRUN=1"
|
||||||
|
|
||||||
|
REM === ROOT FOLDER — leave as %~dp0 to use the folder this bat file lives in ===
|
||||||
|
set "ROOT=%~dp0"
|
||||||
|
|
||||||
REM === GET TODAY'S DATE IN YYYYMMDD FORMAT ===
|
REM === GET TODAY'S DATE IN YYYYMMDD FORMAT ===
|
||||||
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd"') do set TODAY=%%i
|
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd"') do set TODAY=%%i
|
||||||
@@ -10,6 +13,11 @@ for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd"') do
|
|||||||
set "NEWNAME=PT STMT_%TODAY%.txt"
|
set "NEWNAME=PT STMT_%TODAY%.txt"
|
||||||
set "FOLDERNAME=PT STMT_%TODAY%"
|
set "FOLDERNAME=PT STMT_%TODAY%"
|
||||||
|
|
||||||
|
if "%DRYRUN%"=="1" (
|
||||||
|
echo [DRY RUN] No files will be changed.
|
||||||
|
) else (
|
||||||
|
echo [LIVE] Changes will be made.
|
||||||
|
)
|
||||||
echo Processing folders under %ROOT%...
|
echo Processing folders under %ROOT%...
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
@@ -17,29 +25,30 @@ REM === LOOP THROUGH ALL SUBFOLDERS ===
|
|||||||
for /r "%ROOT%" %%d in (.) do (
|
for /r "%ROOT%" %%d in (.) do (
|
||||||
|
|
||||||
if exist "%%d\export.txt" (
|
if exist "%%d\export.txt" (
|
||||||
echo Processing: %%d
|
echo Found: %%d
|
||||||
|
|
||||||
REM pushd into the folder so all commands use short relative paths (fixes path-too-long errors)
|
|
||||||
pushd "%%d"
|
pushd "%%d"
|
||||||
|
|
||||||
REM Rename export.txt
|
if "%DRYRUN%"=="1" (
|
||||||
|
echo RENAME export.txt ^> %NEWNAME%
|
||||||
|
echo MKDIR %FOLDERNAME%
|
||||||
|
echo MOVE %NEWNAME% ^> %FOLDERNAME%\
|
||||||
|
for %%f in ("*.tif") do (
|
||||||
|
echo MOVE %%~nxf ^> %FOLDERNAME%\
|
||||||
|
)
|
||||||
|
) else (
|
||||||
ren "export.txt" "%NEWNAME%"
|
ren "export.txt" "%NEWNAME%"
|
||||||
|
|
||||||
REM Create dated folder
|
|
||||||
mkdir "%FOLDERNAME%" 2>nul
|
mkdir "%FOLDERNAME%" 2>nul
|
||||||
|
|
||||||
REM Move renamed txt file
|
|
||||||
move "%NEWNAME%" "%FOLDERNAME%\"
|
move "%NEWNAME%" "%FOLDERNAME%\"
|
||||||
|
|
||||||
REM Move all .tif files
|
|
||||||
for %%f in ("*.tif") do (
|
for %%f in ("*.tif") do (
|
||||||
move "%%f" "%FOLDERNAME%\"
|
move "%%f" "%FOLDERNAME%\"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
popd
|
popd
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
echo.
|
|
||||||
echo Done.
|
echo Done.
|
||||||
pause
|
pause
|
||||||
|
|||||||
Reference in New Issue
Block a user