Support Forums

Full Version: FileSort v1.00 CMD Script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here's my newest script for sorting files by file extension into different subdirectories within a main directory.

Save this as Anything.cmd:
Code:
@echo off
@color 0B
cls

title Ace FileSort v1.00

set ver=v1.00
set var=0

echo The files in this directory will be moved into different folders
echo.
echo Do you want to continue^?
echo.
echo.   [Y] - Continue
echo.   [Q] - Quit and Exit
echo.

choice /c:YQ>nul
if errorlevel 2 goto Exit
if errorlevel 0 goto Start

:Start
md "%CD%\FileSort %ver%"
md "%CD%\FileSort %ver%\Compressed Archives"
md "%CD%\FileSort %ver%\Image Files"
md "%CD%\FileSort %ver%\Text Files"
md "%CD%\FileSort %ver%\Sound Files"
md "%CD%\FileSort %ver%\Video Files"

:Compressed Files
for %%f in (*.*) do (
if /i "%%~xf"==".rar" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Compressed Archives"
    set /a var+=1
    )
if /i "%%~xf"==".zip" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Compressed Archives"
    set /a var+=1
    )
if /i "%%~xf"==".iso" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Compressed Archives"
    set /a var+=1
    )
if /i "%%~xf"==".bin" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Compressed Archives"
    set /a var+=1
    )
if /i "%%~xf"==".cue" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Compressed Archives"
    set /a var+=1
    )
if /i "%%~xf"==".tar" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Compressed Archives"
    set /a var+=1
    )
if /i "%%~xf"==".gz" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Compressed Archives"
    set /a var+=1
    )
)

:Image Files
for %%f in (*.*) do (
if /i "%%~xf"==".tif" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Image Files"
    set /a var+=1
    )
if /i "%%~xf"==".png" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Image Files"
    set /a var+=1
    )
if /i "%%~xf"==".jpg" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Image Files"
    set /a var+=1
    )
if /i "%%~xf"==".gif" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Image Files"
    set /a var+=1
    )
if /i "%%~xf"==".bmp" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Image Files"
    set /a var+=1
    )
)

:Text Files
for %%f in (*.*) do (
if /i "%%~xf"==".txt" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".doc" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".docx" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".log" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".msg" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".readme" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".rtf" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".text" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".wps" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".wpd" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
if /i "%%~xf"==".pages" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Text Files"
    set /a var+=1
    )
)

:Sound Files
for %%f in (*.*) do (
if /i "%%~xf"==".aif" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".aiff" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".aac" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".au" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".flac" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".ogg" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".ra" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".wave" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".wav" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".wma" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".mp4" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".mp3" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".m4a" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".mid" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".midi" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
if /i "%%~xf"==".mp2" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Sound Files"
    set /a var+=1
    )
)

:Video Files
for %%f in (*.*) do (
if /i "%%~xf"==".wmv" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".avi" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".flv" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".mp4" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".mpg" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".mov" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".3gp" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".divx" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
if /i "%%~xf"==".rm" (
    move "%CD%\%%f" "%CD%\FileSort %ver%\Video Files"
    set /a var+=1
    )
)

cls
echo.
echo You have sorted %var% files. They will be available at this location:
echo.
echo.     ^> "%CD%\FileSort %ver%"
echo.
ping -n 3 127.0.0.1>nul
echo Press any key to finish...
pause>nul

:Exit
That's a great script , just tested it !
Thanks for the share ! : )
No problem, I could have added every possible file extension I could think of but I couldn't be bothered at the time, people are going to use it for general (common) file formats anyway I would assume.
Great job, thank you for it. How long did it take to write this?
Around 10 minutes, not very long at all, I do all sorts of things in batch
Wow, just tried this. Great script.

Good job Cool.
I have another great script that will read files from a text file line by line and delete them when the file is dropped onto the batch file. Just about done with it.
Make sure to post it here when it's done : )