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"]