Skip to content

Instantly share code, notes, and snippets.

@mindfulvector
Last active September 2, 2024 06:53
Show Gist options
  • Save mindfulvector/9976eb5e89b91b3c4bd577df607a59c3 to your computer and use it in GitHub Desktop.
Save mindfulvector/9976eb5e89b91b3c4bd577df607a59c3 to your computer and use it in GitHub Desktop.
organize_zx_spectrum

ZX Spectrum Game Organizer

This batch script is designed to automatically organize a collection of ZX Spectrum game files and related media. It sorts various file types into appropriate directories, making it easier to manage large collections of ZX Spectrum content.

Features

  • Organizes files into categories: games, pokes, images, documents, audio, and miscellaneous
  • Handles common ZX Spectrum file formats (.tap, .tzx, .z80, .sna, .rzx, .dsk) + poke files (.pok)
  • Sorts image files (.jpg, .png, .gif, .bmp)
  • Manages document files (.txt, .pdf)
  • Organizes audio files (.mp3, .ay)
  • Handles ZIP archives based on their content
  • Creates a detailed log file of all operations

Usage

Place the script (organize_zx_spectrum.bat) in the same directory as your ZX Spectrum files.

Double-click the script to run it.

The script will create an Organized_ZX_Spectrum folder with the following subdirectories:

games
pokes
images
documents
audio
misc

Files will be moved to their respective folders based on their file extensions.

A log file (organize_log.txt) will be created, detailing all actions taken by the script.

File Type Sorting

Games: .tap, .tzx, .z80, .sna, .rzx, .dsk
Pokes: .pok
Images: .jpg, .png, .gif, .bmp
Documents: .txt, .pdf
Audio: .mp3, .ay
Misc: All other file types

ZIP files are sorted based on their content (e.g., tap.zip goes to the games folder).

Notes

There will be no output until the script finishes due to limitations of batch files. I'm not sure how to fix this.

The script will not move itself, preventing any issues that could arise from self-deletion.

Always backup your files before running organizational scripts like this one.

Check the log file (organize_log.txt) for details on file movements and any potential issues.

Customization

You can easily modify the script to handle additional file types or change the sorting logic. Look for the if /I "!EXT!"==".xxx" lines in the script and add or modify as needed.

Contributing

Feel free to fork this script and adapt it to your needs. If you make improvements, consider creating a fork and posting a message here to benefit the community.

License

This script is released under the (AGPLv3 License)[https://www.gnu.org/licenses/agpl-3.0.en.html#license-text].

Happy organizing, and enjoy your newly sorted ZX Spectrum collection!

@echo off
echo WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
echo.
echo YOU **MUST** MAKE A BACKUP OF ALL OF YOUR SPECTRUM FILES BEFORE RUNNING THIS SCRIPT!
echo.
echo IF YOU HAVE NOT DONE THIS, PRESS CTRL+C OR CLOSE THIS TERMINAL WINDOW **NOW**.
echo.
echo IF THERE IS ANYTHING AT ALL IN THE FOLDER WHERE THIS SCRIPT IS LOCATED OTHER THAN
echo ZX SPECTRUM GAME FILES, IMAGES, AND RELATED FILES, CLOSE THIS TERMINAL WINDOW **NOW**.
echo.
echo THE DEVELOPER CANNOT BE HELD RESPONSIBLE FOR ANY DAMAGE THIS SCRIPT DOES TO YOUR COMPUTER
echo OR TO FILES OR INDEED TO ANYTHING ELSE AT ALL. PLEASE READ THIS SCRIPT BEFORE YOU RUN IT!
echo.
echo YOU HAVE BEEN WARNNED
echo.
echo WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
echo.
echo.
echo PRESS CTRL+C TO ABORT, OR ENTER TO CONTINUE
pause
setlocal enabledelayedexpansion
:: Set the source and destination directories
set "SOURCE_DIR=%CD%"
set "DEST_DIR=%CD%\Organized_ZX_Spectrum"
set "SCRIPT_NAME=%~nx0"
:: Create a log file
set "LOG_FILE=%CD%\organize_log.txt"
echo Organizing ZX Spectrum files... > "%LOG_FILE%"
:: Create destination directories
mkdir "%DEST_DIR%\games" 2>nul
mkdir "%DEST_DIR%\pokes" 2>nul
mkdir "%DEST_DIR%\images" 2>nul
mkdir "%DEST_DIR%\documents" 2>nul
mkdir "%DEST_DIR%\audio" 2>nul
mkdir "%DEST_DIR%\misc" 2>nul
:: Handle ZIP files
for %%F in ("%SOURCE_DIR%\*.zip") do (
set "FILE=%%~nxF"
echo Processing ZIP: !FILE! >> "%LOG_FILE%"
tar -xf "!FILE!"
REM if /I "!FILE:~-7!"=="tap.zip" (
REM call :MoveFile "%%F" "%DEST_DIR%\games\"
REM ) else if /I "!FILE:~-7!"=="tzx.zip" (
REM call :MoveFile "%%F" "%DEST_DIR%\games\"
REM ) else if /I "!FILE:~-7!"=="z80.zip" (
REM call :MoveFile "%%F" "%DEST_DIR%\games\"
REM ) else if /I "!FILE:~-7!"=="mp3.zip" (
REM call :MoveFile "%%F" "%DEST_DIR%\audio\"
REM ) else if /I "!FILE:~-6!"=="ay.zip" (
REM call :MoveFile "%%F" "%DEST_DIR%\audio\"
REM ) else (
REM call :MoveFile "%%F" "%DEST_DIR%\misc\"
REM )
)
pause
:: Process files
echo Processing files... >> "%LOG_FILE%"
for %%F in ("%SOURCE_DIR%\*") do (
set "FILE=%%~nxF"
set "EXT=%%~xF"
:: Skip the batch file itself
if /I not "!FILE!"=="!SCRIPT_NAME!" (
echo Processing: !FILE! >> "%LOG_FILE%"
if /I "!EXT!"==".tap" (
call :MoveFile "%%F" "%DEST_DIR%\games\"
) else if /I "!EXT!"==".tzx" (
call :MoveFile "%%F" "%DEST_DIR%\games\"
) else if /I "!EXT!"==".z80" (
call :MoveFile "%%F" "%DEST_DIR%\games\"
) else if /I "!EXT!"==".sna" (
call :MoveFile "%%F" "%DEST_DIR%\games\"
) else if /I "!EXT!"==".pok" (
call :MoveFile "%%F" "%DEST_DIR%\pokes\"
) else if /I "!EXT!"==".rzx" (
call :MoveFile "%%F" "%DEST_DIR%\games\"
) else if /I "!EXT!"==".dsk" (
call :MoveFile "%%F" "%DEST_DIR%\games\"
) else if /I "!EXT!"==".jpg" (
call :MoveFile "%%F" "%DEST_DIR%\images\"
) else if /I "!EXT!"==".png" (
call :MoveFile "%%F" "%DEST_DIR%\images\"
) else if /I "!EXT!"==".gif" (
call :MoveFile "%%F" "%DEST_DIR%\images\"
) else if /I "!EXT!"==".bmp" (
call :MoveFile "%%F" "%DEST_DIR%\images\"
) else if /I "!EXT!"==".txt" (
call :MoveFile "%%F" "%DEST_DIR%\documents\"
) else if /I "!EXT!"==".pdf" (
call :MoveFile "%%F" "%DEST_DIR%\documents\"
) else if /I "!EXT!"==".mp3" (
call :MoveFile "%%F" "%DEST_DIR%\audio\"
) else if /I "!EXT!"==".ay" (
call :MoveFile "%%F" "%DEST_DIR%\audio\"
) else (
call :MoveFile "%%F" "%DEST_DIR%\misc\"
)
) else (
echo Skipping batch file: !FILE! >> "%LOG_FILE%"
)
)
echo Organization complete. Files have been moved to %DEST_DIR% >> "%LOG_FILE%"
echo Check %LOG_FILE% for details.
type "%LOG_FILE%"
pause
goto :EOF
:: Function to move file
:MoveFile
set "src=%~1"
set "dst=%~2"
echo Moving "%src%" to "%dst%" >> "%LOG_FILE%"
move "%src%" "%dst%" >> "%LOG_FILE%" 2>&1
if errorlevel 1 (
echo Failed to move "%src%" to "%dst%" >> "%LOG_FILE%"
) else (
echo Successfully moved "%src%" to "%dst%" >> "%LOG_FILE%"
)
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment