[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to remove pathname from a filename

Posted on 2011-04-22
6
Medium Priority
?
468 Views
Last Modified: 2012-05-11
Hi Experts,

I want to remove the pathname from a filename.

./path/name/file.txt
I want to change this to just file.txt ( everything upto the last / should be removed)

How can I do it.

Thanks,
0
Comment
Question by:ambuli
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
tel2 earned 1000 total points
ID: 35451706
Hi ambuli,

In Perl, let's assume the path is in a $pathname variable:
    $pathname = './path/name/file.txt';
You could then do this:
    ($filename = $pathname) =~ s|.*/||/;
    print $filename;
The (tested) output is:
    file.txt
0
 

Author Comment

by:ambuli
ID: 35451708
Thanks you
0
 
LVL 12

Expert Comment

by:tel2
ID: 35451709
Sorry, remove the last "/", so the substitution line reads:
    ($filename = $pathname) =~ s|.*/||;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ambuli
ID: 35451714
Hi tel2,

I am getting syntax errors.

syntax error at searchLogs.pl line 51, near "/;"
0
 
LVL 12

Expert Comment

by:tel2
ID: 35451719
I know. ambuli.  Did you read my 2nd post, above?
0
 

Author Comment

by:ambuli
ID: 35451798
Sorry, I did not check that before.  Yes, it is working fine.  Thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question