CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



birdy
Novice

Mar 13, 2008, 8:28 AM

Post #1 of 4 (3006 views)
to parse a filename from a pathname Can't Post

Hello,,

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???


KevinR
Veteran


Mar 13, 2008, 11:35 AM

Post #2 of 4 (3002 views)
Re: [birdy] to parse a filename from a pathname [In reply to] Can't Post

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.
-------------------------------------------------


birdy
Novice

Mar 13, 2008, 1:03 PM

Post #3 of 4 (3000 views)
Re: [KevinR] to parse a filename from a pathname [In reply to] Can't Post

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!!!


birdy
Novice

Mar 13, 2008, 1:07 PM

Post #4 of 4 (2999 views)
Re: [birdy] to parse a filename from a pathname [In reply to] Can't Post

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

Thanks.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives