Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
to parse a filename from a pathname


Mar 13, 2008, 8:28 AM

Views: 4830
to parse a filename from a pathname


I need to travel a root directory and its sub directories to grab all.pdf files. I have the restriction of not being able to download modules on th eunix box accept for the stadard module. so using the following line of cod eto grab the list of files:

@filelist=`find $source_dir -name "*.pdf"`;

#print @filelist;
foreach $files(@filelist)
print "\n $files";

no wthe problem i sthat I need to strip th eFilename with all the dir and sub dir in fo.

As I am new to Perl having a hard time coding it out. Can anyone please help me with the code???


Mar 13, 2008, 11:35 AM

Views: 4826
Re: [birdy] to parse a filename from a pathname

use the File::Basename module, it is a core module that comes with perl. You could also use File::Find (also a core module) instead of shelling to the find command to find all the pdf files.


Mar 13, 2008, 1:03 PM

Views: 4824
Re: [KevinR] to parse a filename from a pathname

ya i had already tried the File::Find command,

the problem with tah wa seven though it worked on command line and gave correct results in th escript it was passing null value sto the array that I wa sussing to store the values.

As i am new I couldnt understand teh reason behindit and so used the above method.

let me try the basename an dI will let you know how it works!!!


Mar 13, 2008, 1:07 PM

Views: 4823
Re: [birdy] to parse a filename from a pathname

thanks basename works!!! I have been stuck at this point for so long.....tried so forums. You helped in one shot.