Thursday, January 13, 2011

How to Sort Out Files of Differnet Types with Help of Batch Files

Have you got directories with thousands and thousands of unsorted files? Sure everyone has. I also have folder called 'Downloads' where I place almost everything downloaded from the Web. Usually I clear it once or twice per month and then start to fill it with 'digital garbage' again. But in this case I often lose gems among the garbage, that's this week I decided to sort files in 'Downloads' instead of removing them. I didn't want to lose my time and started Dr.Batcher to create the batch file which had to sort everything without my additional effort. I won't waste your time describing what I tried to do, just give you the code that was created after some experiments.

@ECHO off
REM Creating folders to separate files of different types
IF not EXIST TXT MD TXT
IF not EXIST AVI MD AVI
IF not EXIST MP3 MD MP3
IF not EXIST JPG MD JPG
IF not EXIST RAR MD RAR
IF not EXIST HTM MD HTM
IF not EXIST EXE MD EXE
ECHO Moving text files
MOVE /-Y *.txt TXT
MOVE /-Y *.doc TXT
MOVE /-Y *.rtf TXT
MOVE /-Y *.PDF TXT
ECHO Moving movies
MOVE /-Y *.avi AVI
MOVE /-Y *.mpg AVI
MOVE /-Y *.divx AVI
MOVE /-Y *.xvid AVI
ECHO Moving audio
MOVE /-Y *.mp3 MP3
MOVE /-Y *.wav MP3
MOVE /-Y *.ogg MP3
MOVE /-Y *.wma MP3
ECHO Moving images
MOVE /-Y *.jpg JPG
MOVE /-Y *.bmp JPG
MOVE /-Y *.gif JPG
MOVE /-Y *.png JPG
ECHO Moving archives
MOVE /-Y *.RAR RAR
MOVE /-Y *.ZIP RAR
MOVE /-Y *.gz RAR
MOVE /-Y *.7z RAR
ECHO Moving executables
MOVE /-Y *.exe EXE
ECHO Everything is sorted!
PAUSE

As far as you can see, this script is quite simple though it is long enough. This Flag '/-Y' is added to avoid replacing one file existing in a target folder with a new file with the same name. Hope you'll find this script useful.

1 comment:

  1. This is awesome! Just a few tweaks and I'll be set. :D Thanks.

    ReplyDelete

Translate