Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Cleaning up directory paths, from strings containing multiple instances of directory path+filename

by Amphiaraus (Sexton)
on Oct 18, 2012 at 20:26 UTC ( #999819=perlquestion: print w/replies, xml ) Need Help??
Amphiaraus has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to remove directory paths from directory path + filename strings, leaving the filename only, if more than one directory path + filename string occur as substrings within a larger string?

Example:

Can this string-

with arguments [/C move /Y "E:/Atlas/12_4_0_US/AppImage/Bin/Installed +Providers/VehicleRecords/VehicleRecordUpdateUtility.exe" "E:/Atlas/12 +_4_0_US/EngPublish"]

.. be changed to this string-

with arguments [/C move /Y "VehicleRecordUpdateUtility.exe" "EngPublis +h"]

The above arguments are concerned with moving a file named "VehicleRecordUpdateUtility.exe" to a folder named "EngPublish"

Thank You,

Amphiaraus

  • Comment on Cleaning up directory paths, from strings containing multiple instances of directory path+filename
  • Select or Download Code

Replies are listed 'Best First'.
Re: Cleaning up directory paths, from strings containing multiple instances of directory path+filename
by toolic (Bishop) on Oct 18, 2012 at 20:49 UTC
    use warnings; use strict; use File::Basename; my $str = 'with arguments [/C move /Y "E:/Atlas/12_4_0_US/AppImage/Bin +/Installed Providers/VehicleRecords/VehicleRecordUpdateUtility.exe" " +E:/Atlas/12_4_0_US/EngPublish"]'; $str =~ s/"(.*?)"/'"' . basename($1) . '"'/eg; print "$str\n"; __END__ with arguments [/C move /Y "VehicleRecordUpdateUtility.exe" "EngPublis +h"]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999819]
Approved by bart
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2016-12-02 20:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (50 votes). Check out past polls.