Do you know where your variables are? | |
PerlMonks |
Path parsing from full to relativeby Kaplah (Initiate) |
on Jun 20, 2018 at 19:56 UTC ( [id://1217048]=perlquestion: print w/replies, xml ) | Need Help?? |
Kaplah has asked for the wisdom of the Perl Monks concerning the following question:
Greetings all. I was wondering how I would accomplish the following. Given a full file path how can I trim it down to the last folder? For instance: C:\somedirectory\anotherDirectory\WorkingDirectory\myFile.txt C:\somedirectory\anotherDirectory\WorkingDirectory\Logs\myLogs.txt C:\somedirectory\anotherDirectory\WorkingDirectory\Stuff\myStuff.txt needs to become: \WorkingDirectory\myFile.txt \WorkingDirectory\Logs\myLogs.txt \WorkingDirectory\Stuff\myStuff.txt The trick here is that the directories are not hard coded. My only life saver is that the "WorkingDirectory" has a naming standard and starts with the same three characters (for argument "ABC"). Is there a way to grab this folder once and then build the other strings? Or can I pull the reverse and subtract the unwanted beginning portion out of my path string? How would I do this?
Back to
Seekers of Perl Wisdom
|
|