astroboy has asked for the wisdom of the Perl Monks concerning the following question:
A while back I wrote a script that needed to pull out file names from an input line (including the full path) and convert them into the short name equivalent, E.g.:
C:\Program Files\Application Name\bin\app.exe > C:\Program Files\Application Name\log\app.logwould become
C:\PROGRA~1\APPLIC~1\bin\app.exe > C:\PROGRA~1\APPLIC~1\log\app.logI should point out that the line format could vary. In the case above, a script redirects its output to a log file, but the line may consist of a filename, followed by three other filenames that may be arguments passed to the first file.
Now, getting the short name is easy, I'd just pass the name to Win32::GetShortPathName. However, I never came up with a way to pull out the file names in the first place. In the end, I gave up, and just made it mandatory that the input only had the short names.
I never posted to Perlmonks at the time, cos I didn't want to admit defeat, but this has been nagging at me for a while now, and it's time to come, hat in hand: how do I do this?
UPDATE: Wow, I seem to be confusing people. I hope this explains things: I have a file where each line can contain Windows filenames. I gave two examples, but infact I have no way of knowing in advance what the line will look like. All I know is that
Update 2: Effectively what I've done is written cron for windows. I read the crontab and schedule each line. Unfortunately, the crontab lines can't contain long names. I need short names, so I was hoping for a regex of some sort that could do this for me.
Ultimately, the line will be passed to cmd.exe - so the line can contain anything that cmd can (except long file names - but this is not related to cmd). I'm really bad at regexes. Nothing I've tried comes even close to what I want - which is why I haven't posted anything. As I said, I didn't post to Perlmonks before (I wrote this cron over a month ago), cos I knew I would be asked for my regex attempts, and I was ashamed of my regex feebleness
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing a list or Win32 filenames
by ikegami (Patriarch) on Sep 09, 2004 at 20:46 UTC | |
by astroboy (Chaplain) on Sep 09, 2004 at 22:35 UTC | |
|
Re: Parsing a list or Win32 filenames
by bobf (Monsignor) on Sep 09, 2004 at 18:29 UTC | |
by astroboy (Chaplain) on Sep 09, 2004 at 18:37 UTC | |
|
Re: Parsing a list or Win32 filenames
by ikegami (Patriarch) on Sep 09, 2004 at 18:40 UTC | |
|
Re:Parsing a list or Win32 filenames
by bobf (Monsignor) on Sep 09, 2004 at 19:06 UTC | |
by astroboy (Chaplain) on Sep 09, 2004 at 19:21 UTC |