Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 14th, 2013, 12:29 AM
dazz100 dazz100 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 12 dazz100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 23 sec
Reputation Power: 0
Help : Trying to use Find::File::Rule ???

Hi

Below is a simple test program. The end use of this program is to produce a list of sub directories sorted by age. The age of the sub directories is identifed by the names which have the format:

YYYYMMDD-HHMM

There is only one layer of sub directories.

I want to produce the list to allow me to sequencially delete the sub directories starting with the oldest. This is part of a script to purge older directories and files in a system where there is a stream of image files being produced. The incoming images will be dropped into new sub directories created on each day.

There are other sub directories in the base directory that are not named by the date format. I don't want to delete these. The regex filter needs to work.

The problem I have is that I can't get the Find::File::Rule call to filter on the sub directory naming format. I have tried different things to get the regex string to work but it doesn't. I am stuck.

Code:
#!/usr/bin/perl 
# =========================================================== 
use warnings;
use strict;
use File::Find::Rule;

my $dir_path = "/var/images/";
my $filter = '/\d{8}-\d{4}$/';


#my @folders = reverse sort File::Find::Rule->directory->in( $dir_path );
#my @folders =  File::Find::Rule->directory->name($filter)->in( $dir_path );
my @folders =  File::Find::Rule->directory->in( $dir_path );

foreach my $i (@folders){
  print "$i\n";
}


The program above produces produces the output below. The code works as written but I can't get it to do what I want. I haven't yet got to the point of sorting the list.


Code:
dazz@alpha:~$ ./directory_lister.pl
/var/images
/var/images/20130110-2259
/var/images/20130112-1003
/var/images/20130108-2115
/var/images/20130108-2228
/var/images/current
/var/images/20130108-2105
/var/images/20130108-2131
/var/images/20130109-2344
/var/images/20130109-2345
/var/images/lost+found
/var/images/20130108-2107
/var/images/20130108-2132
/var/images/20130108-2109
/var/images/20130111-2304
/var/images/20130108-2135
/var/images/20130109-2340
/var/images/20130108-2125
/var/images/20130109-2300
/var/images/20130108-2233
/var/images/20130108-2054
/var/images/test
/var/images/smallsample
/var/images/20130108-2055
dazz@alpha:~$

Reply With Quote
  #2  
Old January 14th, 2013, 09:07 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 36 m 34 sec
Reputation Power: 3885
Use qr// to quote regular expressions. i.e.
Code:
my $filter = qr/\d{8}-\d{4}$/;

Reply With Quote
  #3  
Old January 14th, 2013, 11:21 PM
dazz100 dazz100 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 12 dazz100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 23 sec
Reputation Power: 0
Quote:
Originally Posted by ishnid
Use qr// to quote regular expressions. i.e.
Code:
my $filter = qr/\d{8}-\d{4}$/;


Perfect

Thanks

Dazz

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Help : Trying to use Find::File::Rule ???

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap