Home » Questions » Computers [ Ask a new question ]

How to create new folders and put a file on it

How to create new folders and put a file on it

In order to match the criteria of a "coverflow" like soft I have to create a specific folder (named "name_of_the_film") for each film.avi and cover.jpg I have in my film directory :

Asked by: Guest | Views: 88
Total answers/comments: 1
Guest [Entry]

"I'm not aware of any apps which do this, but you can write a short Perl or Python script to do this for you. The following perl script should do what you need:

use File::Copy;

my $baseDir = ""D:/film/"";

opendir my $dir, $baseDir or die ""Cannot open directory: $!"";
my @files = readdir $dir;

foreach my $file (@files)
{
$fileName = $1 if ($file =~ /^(.*)\.[^\.]+$/i);
mkdir(""$baseDir/$fileName"") unless (-d ""$baseDir/$fileName"");
move(""$baseDir/$file"", ""$baseDir/$fileName/$file"");
}

Assuming you have perl installed, save this script as CreateMovieFolders.pl and then run perl CreateMovieFolders.pl from the command-line."