Add dry run mode and auto root path via %~dp0
This commit is contained in:
@@ -42,12 +42,32 @@ ROOT\
|
||||
|
||||
### Setup
|
||||
|
||||
1. Open `Rename and Move PT STMT.bat` in Notepad
|
||||
2. Set the `ROOT` variable to your actual folder path:
|
||||
```bat
|
||||
set "ROOT=C:\Users\Melissa\Documents\Patients"
|
||||
```
|
||||
3. Save and double-click to run
|
||||
1. Place `Rename and Move PT STMT.bat` in the root patient folder
|
||||
2. Double-click to run — it automatically uses the folder it lives in as the root
|
||||
|
||||
### Dry 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
|
||||
|
||||
|
||||
+26
-17
@@ -1,8 +1,11 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM === SET YOUR ROOT FOLDER HERE ===
|
||||
set "ROOT=C:\path\to\patient"
|
||||
REM === SET TO 1 TO PREVIEW WITHOUT MAKING CHANGES, 0 TO RUN FOR REAL ===
|
||||
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 ===
|
||||
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 "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.
|
||||
|
||||
@@ -17,29 +25,30 @@ REM === LOOP THROUGH ALL SUBFOLDERS ===
|
||||
for /r "%ROOT%" %%d in (.) do (
|
||||
|
||||
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"
|
||||
|
||||
REM Rename export.txt
|
||||
ren "export.txt" "%NEWNAME%"
|
||||
|
||||
REM Create dated folder
|
||||
mkdir "%FOLDERNAME%" 2>nul
|
||||
|
||||
REM Move renamed txt file
|
||||
move "%NEWNAME%" "%FOLDERNAME%\"
|
||||
|
||||
REM Move all .tif files
|
||||
for %%f in ("*.tif") do (
|
||||
move "%%f" "%FOLDERNAME%\"
|
||||
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%"
|
||||
mkdir "%FOLDERNAME%" 2>nul
|
||||
move "%NEWNAME%" "%FOLDERNAME%\"
|
||||
for %%f in ("*.tif") do (
|
||||
move "%%f" "%FOLDERNAME%\"
|
||||
)
|
||||
)
|
||||
|
||||
echo.
|
||||
popd
|
||||
)
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Done.
|
||||
pause
|
||||
|
||||
Reference in New Issue
Block a user