473,563 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching for a File

11 New Member
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
5 1842
KevinADC
4,059 Recognized Expert Specialist
are you searching in one folder or do you need to search in sub folders too?
Feb 23 '07 #2
bir
11 New Member
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
4,059 Recognized Expert Specialist
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
bir
11 New Member
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
bir
11 New Member
Thanks Kevin i'm done with it.
Feb 24 '07 #6

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

Similar topics

2
2517
by: John | last post by:
Hi everyone ! This is a first time I post a message here. If I post my message in a wrong group. Please ignore it. I am trying to build a website which allows users (can be thousands of users, supposedly) to upload their files to their designaged directories (max 15 files for each user). A super user (can be more than one) want to search...
3
7239
by: hivie | last post by:
I have a problem that is causing me problems. I have a text file that stores 5 lines of crap (stuff that I dont need( for the user only)). After that there is data that is in three columns separated by lots of whitespace. I dont think that the bytes are uniform ( I tried TextReader.readblock). Sorry, I am using VC++ .net. I only need the...
4
1637
by: James | last post by:
We have a need to search through an entire drive for a specific file name. The process is currently written with recursive loops through each directory and the Scripting.FileSystemObject. Problem is, it takes forever. When I do a standard file search through Windows Explorer, it typically finds the file I'm looking for within 5 seconds. Is...
3
2084
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
2
2376
by: angus | last post by:
hello everybody, i'm having some problems searching a text file and then deleting the line. since i used fileopen(), i can use the eof() function to loop through the file, searching for the specified line. the problem is, once found, i can't delete it because the filemode is in openmode.input. is there a way to chance the openmode on the...
7
2610
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search string will often not produce a direct match, the results will be based on proximity (50%, 20% 100%, etc). are there any good examples out there...
4
5325
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given the Identifier. The logical way would be to read the record once and put it in an STL container such as vector and then use lower_bound to search for...
12
2359
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A registry mark given by underwriters (as at Lloyd's) to ships in first-class condition. Inferior grades are indicated by A 2 and A 3. () The first...
5
3534
by: Sevla | last post by:
hello guys i set this code , and i would like to know if its possible set "quotes" on the searched word. Thank You #word searching program within a txt file #!C:/perl/bin/perl.exe start:
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.