Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Very useful indeed' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Very useful indeed
Authored by: eagle on Oct 19, '01 10:10:26AM
I wrote a QnD (Quick-and-Dirty) script (link) to recognize .doc and .xls files by their extension. Combined with SetFile and ScriptGUI, I can now double-click on MS Office files and have them auto-load into AppleWorks and be properly translated for me. Very cool. All made possible by the SetFile Developer tool.

[ Reply to This | # ]
Use rindex to eliminate loop
Authored by: houchin on Oct 19, '01 01:34:21PM

Great idea!

To improve the script, why don't you just use rindex to get the last period, instead
of looping through the filename. Also, you should probably verify that the files
does have an extension. Here's some code to replace the while loop at the beginning:

$start = rindex($file, ".");
die "Unknown file extension: $file\n" if ($start == -1);
$ext = substr($file,$start + 1);

(due to problems with backslashes in comments, make sure it's $file[backslash]n in the die statement



[ Reply to This | # ]
Use rindex to eliminate loop
Authored by: eagle on Oct 20, '01 02:48:35PM

Thanks for the suggestion. I didn't know about rindex(). I have changed my code per your recommendation.



[ Reply to This | # ]