Here is a PHP script to automate it:
Code:
<?php
$path = ".";
$extensions = array( "mp4" );
$files = array_diff(scandir($path), array('.', '..'));
foreach ( $files as $file ) {
if ( ! is_file ( $file ) ) continue;
$file_parts = pathinfo( $file );
if ( ! in_array( $file_parts['extension'], $extensions ) ) continue;
if ( ! file_exists( $file_parts['filename'] ) && ! mkdir( $file_parts['filename'] ) ) { echo "Oops! Could
not create directory {$file_parts['filename']}\n"; continue; }
$new_loc = $file_parts['filename'] . "/" . $file;
if ( ! file_exists( $new_loc ) && ! rename( $file, $new_loc ) ) { echo "Oops! Could not move {$file} to {$
new_loc}\n"; continue; }
echo $file . " moved to {$new_loc} successfully.\n";
}
Before:
Quote:
-bash-4.1$ ll
total 4
-rw-rw-r-- 1 admin www-data 0 Jan 10 17:50 2BTB_061209_Cindy.mp4
-rw-rw-r-- 1 admin www-data 0 Jan 10 17:51 2BTB_061211_Mia.mp4
-rw-rw-r-- 1 admin www-data 0 Jan 10 17:51 2BTB_061219_Aaliyah.mp4
-rw-rw-r-- 1 admin www-data 662 Jan 10 17:49 greenguy_help.php
|
After:
Quote:
-bash-4.1$ php greenguy_help.php
2BTB_061209_Cindy.mp4 moved to 2BTB_061209_Cindy/2BTB_061209_Cindy.mp4 successfully.
2BTB_061211_Mia.mp4 moved to 2BTB_061211_Mia/2BTB_061211_Mia.mp4 successfully.
2BTB_061219_Aaliyah.mp4 moved to 2BTB_061219_Aaliyah/2BTB_061219_Aaliyah.mp4 successfully.
-bash-4.1$ ll
total 16
drwxrwsr-x+ 2 admin www-data 4096 Jan 10 17:51 2BTB_061209_Cindy
drwxrwsr-x+ 2 admin www-data 4096 Jan 10 17:51 2BTB_061211_Mia
drwxrwsr-x+ 2 admin www-data 4096 Jan 10 17:51 2BTB_061219_Aaliyah
-rw-rw-r-- 1 admin www-data 662 Jan 10 17:49 greenguy_help.php
|