473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Searching for a File

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
5 1833
KevinADC
4,059 Expert 2GB
are you searching in one folder or do you need to search in sub folders too?
Feb 23 '07 #2
bir
11
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 Expert 2GB
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
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
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
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...
3
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...
4
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...
3
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
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...
7
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...
4
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...
12
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...
5
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.