- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl 5.6.1 File::Find
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 03:30 PM
07-25-2002 03:30 PM
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 05:28 PM
07-25-2002 05:28 PM
SolutionWhen you are learning, I am a firm beliver in not giving away everything but I will get you started. What you need is the -e (file exists) condition.
I'll assume that your filenames are in an array ,$arry.
This is how to find a file in directory $destdir;
use constant FALSE => 0;
use constanr TRUE => 1;
my $i = 0;
my $fnd = FALSE;
my $destdir = "/dest";
my $fullname = "";
while ($i <= $#arry && !fnd)
{
$fullname = $destdir . "/" . $arry[$i];
$fnd = (-e $fullname);
if (!($fnd))
{
++$i;
}
}
if ($fnd)
{
printf("File %s found\n",$fullname);
}
Now searching subdirectories would require another array but this should get you started.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 08:26 PM
07-25-2002 08:26 PM
Re: Perl 5.6.1 File::Find
Thanks for your reply. I was able to find the files in the "base" directory. I can't search the sub-directories in the same loop? I could setup separate searches for each sub-directory, but I was hoping there was an easier/faster way to get it in one look.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 08:59 PM
07-25-2002 08:59 PM
Re: Perl 5.6.1 File::Find
perl does support recursive function calls. That is one way to handle any tree structured data.
But I believe File::Find has a way to walk subdirectories and maintain its context.
Good Luck
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 05:46 AM
07-26-2002 05:46 AM
Re: Perl 5.6.1 File::Find
attached you may find a very crude example I wrote which may come close to what you want, or at least gets you started.
First, even this scriplet is very tiny you should always use the warning flag (i.e. '-w' in the shebang), or if you use Perl > 5.6.X better the 'use warnings' pragma, and *always* the 'use strict' pragma.
These two save you a lot of headache later when your scripts become larger.
Maybe a word to the use of the File::Find module (which is standard in every current Perl installation and needs not to be installed separately).
The module's find() function takes at least two arguments, of which the first is a subroutine reference (in Perl lingo a sub ref), and all that follows a list of starting paths from where find() should decend in your filesystem tree.
The sub ref is a reference to a so called callback function (you can name it anything you like, only used callback here to make it obvious).
In fact it even could be an anonymous sub ref (which has no name), which would be more suitable in my example, since the sub is very short.
You get a reference to any Perl type by prepending a backslash (this is the easy way, there are others also).
For a sub \& gets the reference.
Now find calls this callback sub each time it gets a file (i.e. Unix file, which is anything) while it decends, and keeps the basename in the special variable $_.
But to make the file tests like for existence (with '-e') we need the full path name, which is stored in $File::Find::name (this is a funny way in Perl to address the variable in a different namespace).
In your callback you do anything which is required (e.g. testing, taking sizes, sorting, parsing etc) for your objective.
Here I just populate the hash %found which gets the basename as key and the pathname as value.
Beware, my matching may fail, because it is very crude (at the shell type "perldoc perlre")
HTH
Ralph
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2002 09:14 AM
07-26-2002 09:14 AM
Re: Perl 5.6.1 File::Find
Steve