Created
October 8, 2025 11:44
-
-
Save tomesparon/74069f66fcfd5f41ba814a976cdac1d6 to your computer and use it in GitHub Desktop.
A batch script to take in .raw files and put in folders with Initial and Surname - For CT raw - can be modified for other files with a name convention similar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal EnableExtensions EnableDelayedExpansion | |
| cls | |
| @pushd %~dp0 | |
| REM HOW TO USE: Either drag and drop the folder eg CRAFT onto bat and let it run, or | |
| REM open in powershell / cmd and add the full path as first arg | |
| REM Optional argument: source folder. Defaults to current folder. | |
| set "SRC=%~1" | |
| if not defined SRC set "SRC=%cd%" | |
| if not exist "%SRC%\" ( | |
| echo Source folder not found: "%SRC%" | |
| exit /b 1 | |
| ) | |
| pushd "%SRC%" >nul 2>&1 || ( | |
| echo Cannot access "%SRC%" | |
| exit /b 1 | |
| ) | |
| set "moved=0" | |
| REM Process .raw files (case-insensitive on Windows) | |
| for %%F in (*.raw *.RAW) do ( | |
| if exist "%%~fF" ( | |
| set "surname=" | |
| set "firstname=" | |
| set "name=%%~nF" | |
| REM Extract Surname and Firstname from the start of the filename (delimited by dots) | |
| for /f "tokens=1,2 delims=." %%a in ("!name!") do ( | |
| set "surname=%%a" | |
| set "firstname=%%b" | |
| ) | |
| if defined surname if defined firstname ( | |
| set "initial=!firstname:~0,1!" | |
| set "folder=!initial!!surname!" | |
| if not exist "!folder!\" mkdir "!folder!" >nul 2>&1 | |
| REM echo Moving "%%~nxF" | |
| move /y "%%~fF" "!folder!\" >nul 2>&1 | |
| if not errorlevel 1 set /a moved+=1 | |
| ) else ( | |
| echo Skipping "%%~nxF" (unexpected name pattern; expected Surname.Firstname...) | |
| ) | |
| ) | |
| ) | |
| if "%moved%"=="0" echo No matching .raw files moved in "%SRC%". | |
| echo Moved %moved% .raw files into named folders | |
| popd >nul 2>&1 | |
| endlocal | |
| @popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment