By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

Searching for a File

P: 11
I have a folder which contains the xml files with the word CICM in the filename (can also contain some other files)

I need to search for all these xml files and create a single zip file for all these xml's.

Currently i tried searching using the $File::Find. Please correct me in my code here or else if there's any other better option available.

Expand|Select|Wrap|Line Numbers
  1. #Searching for the CICM files in CICM data folder
  2. find(sub {
  3.     return if ($_ =~/^CICM/i);
  4.     return unless ($_ =~/\.xml/i);
  5.     stat $File::Find::name;
  6.     return if -d;
  7.     return unless -r;
  8.  
  9.     open FILE, "< $File::Find::name" or return;
  10.     my $file_name_string = <FILE>;
  11.     push @find_file_name, $file_name_string;
  12.     close (FILE);
  13.  
  14.     print "@find_file_name \n";
  15. }, $User_Preferences{"UNMASKED_DATA_FOLDER"});
  16.  
The print in the sub is not working.
Feb 23 '07 #1
Share this Question
Share on Google+
5 Replies


KevinADC
Expert 2.5K+
P: 4,059
are you searching in one folder or do you need to search in sub folders too?
Feb 23 '07 #2

P: 11
bir
are you searching in one folder or do you need to search in sub folders too?
Hey i'm searching in 1 folder only....
Feb 24 '07 #3

KevinADC
Expert 2.5K+
P: 4,059
give this a try:

Expand|Select|Wrap|Line Numbers
  1. my $dir = 'path/to/dir';
  2. opendir(DIR,$dir) or die "$!";
  3. my @files = grep { /^.*?CICM.*?\.xml$/i} readdir DIR;
  4. close DIR;
  5.  
Feb 24 '07 #4

P: 11
bir
give this a try:

Expand|Select|Wrap|Line Numbers
  1. my $dir = 'path/to/dir';
  2. opendir(DIR,$dir) or die "$!";
  3. my @files = grep { /^.*?CICM.*?\.xml$/i} readdir DIR;
  4. close DIR;
  5.  
Hi

This doesn't seem to be working....i tried it out! Can u please tell me how to search a for a file names in lines of my earlier stated problem
Feb 24 '07 #5

P: 11
bir
Thanks Kevin i'm done with it.
Feb 24 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.