CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Organizing Files Using Regular Expressions: Edit Log



valefor
New User

Aug 25, 2011, 2:03 AM


Views: 7032
Organizing Files Using Regular Expressions

I have a number of files that I want to organize into their own folders based on part of their filename. So far I've managed to read in all of the files in said directory properly, but for whatever reason the regular expressions that I'm using to match the filenames and strip off the unnecessary portions of the filename to create the directory names aren't working properly. Specifically, it's returning things that I did not specify, such as folders and patterns that don't match the regex that I set up, and it doesn't seem to be lopping off characters properly in the $FolderName variable.

Here's what I have so far:


Code
#!/usr/bin/perl -w 

use strict;
use 5.010;
use File::Find::Rule;
use File::Path;
use File::Copy;


my $interesting = File::Find::Rule->new->file()->name(qr/\[*\]*\.*$/)->start('.');

while ( my $perl_file = $interesting->match ) {
my $FolderName = $perl_file;
$FolderName =~ m/](.*?)-/;
print $FolderName . "\n";
}


To avoid potentially screwing up the folder structure while I'm working this out I'm just printing off the folder name rather than moving stuff.


(This post was edited by valefor on Aug 25, 2011, 2:07 AM)


Edit Log:
Post edited by valefor (New User) on Aug 25, 2011, 2:07 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives