Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FileSort v1.00 CMD Script
#1
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
Reply
#2
That's a great script , just tested it !
Thanks for the share ! : )
Reply
#3
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.
Reply
#4
Great job, thank you for it. How long did it take to write this?
Reply
#5
Around 10 minutes, not very long at all, I do all sorts of things in batch
Reply
#6
Wow, just tried this. Great script.

Good job Cool.
Reply
#7
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.
Reply
#8
Make sure to post it here when it's done : )
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FileTerminator Batch/CMD Script AceInfinity 1 993 08-31-2011, 11:11 PM
Last Post: Prominent
  [Video Tutorial] How to add Cmd Prompt to Context Menu (Right-Click) AceInfinity 37 16,619 04-19-2011, 06:32 AM
Last Post: Spectrum
  How To Run CMD (Command Prompt) From *Anywhere* Resistance 8 7,227 03-20-2011, 02:11 PM
Last Post: AceInfinity
  Deleting Locked Fies Manually - Windows CMD. UID=0 3 3,532 11-25-2010, 09:58 PM
Last Post: AceInfinity

Forum Jump:


Users browsing this thread: 1 Guest(s)