Moving files to sub-dirs based on extenstions
Posted on 2008-06-10
I need a Perl script to do the following...
1. I have a collection of 40000+ audio and video files scattered across a file system. I would like to run a Perl script from a directory that does the following...
2. Search for ALL audio and video files located in the current directory and move them to sub-directories named on the file extension. Thus, all .mp3 files go into a sub-dir named mp3, .avi got into a sub-dir named avi
3. The sub-dirs named after the audio-video file extensions may or may not pre-exist in a directory. Some of the audio video files I have seen are: .mp3, .asf, .mp4, .m4v, .mov, .avi, .wmv, .mpg, .mpeg, .rax. This is not a complete set, and the developer should use a list of the commonly known audio video extensions.
4. Any directory may have further sub-directories that are NOT named after the audio video extension names. If this happens, the script should traverse down into such directories and search for audio video files and execute step 2 above again...
5. Thus, at the end of he script run, there will be directories named avi / mp3 / mpg / etc located in multiple directories. None of these directories can be empty, if an empty audio video directory is found anywhere (it probably pre-existed) with no audio or video files in it, such a directory should be deleted.
Please ask if you have any questions.