laziness, impatience, and hubris | |
PerlMonks |
Inelegant code to compare file namesby davies (Prior) |
on Sep 21, 2011 at 19:30 UTC ( [id://927209]=perlquestion: print w/replies, xml ) | Need Help?? |
davies has asked for the wisdom of the Perl Monks concerning the following question: TIMTOWTDI, in Excel as in Perl. Excel usually has two ways of doing anything. What gets my goat is that those two ways are usually utterly incompatible. When processing Excel files with Win32::OLE, I always create an instance of Excel in my Perl code, and strongly recommend this practice. Unfortunately, this does not stop Excel opening files itself before any files the user designates - add-ins would fall into this category. This means that the Perl instance of Excel may have several files open. Excel's next quirk is that the filename it holds in the VBProjects collection may well be different from the filename given by the user. There are three main causes of differences. The first is that the user may not have specified a directory. Excel will add a fully qualified path. The second is that the user may not have specified an extension. He knows, after all, that the file has no extension. Windows tells him this. No-one has mentioned the option to hide extensions for registered file types, which means that he never sees ".xls". The third is that he may be using a mapped network drive. This Excel will convert from the mapped name to an unmapped, fully qualified name. The following code is my attempt to compare two file names in these different formats. It works for everything I've tried, but I'm sure that there is a better way, probably involving regexes.
Any advice would be appreciated, especially pointers to further reading. The intention of the code is to take everything after the last backslash (if there is one) up to the last dot (if there is one after the last backslash) and to compare this for each string. TIA & regards, John Davies Update: a /msg has pointed out (correctly AFAICT without more extensive testing) that launching Excel with the /s option prevents loading of add-ins and personal.xls. There are other ways of loading files, such as VBA references, that I haven't tested. My fear on this is that there are some ways to drag files into an instance somewhere in the depths of Excel (possibly versions yet to be released) that I haven't met.
Back to
Seekers of Perl Wisdom
|
|