I'm sure there are tricks to speed up AS's folding, spindling, and
mutilating of strings, but once you've gone to all the trouble of
firing up the shell, it seems a shame to use it to do nothing but turn
around and fire up PHP, especially for something as simple as
basename/dirname (which is what I assume you meant, since I don't know
of any PHP function called 'filename').
First of all, once you have a file, you can just get its containing folder directly from the Finder:
set someFile to (choose file)
tell application "Finder"
set dirname to folder of someFile
set basename to name of someFile
end tell
which, since Finder is always running, should be faster even than the
shell alternatives. The resulting value in "dirname" is a Finder folder
object, not a pathname, but that's easily rectified if you need the
latter:
set dirname to POSIX path of (folder of someFile as alias)
Using basename with the optional second argument to strip suffixes, on the other hand, is rather more verbose in native AS.
Other solutions:
1. Instead of running the PHP interpreter, just run the special
commands basename or dirname, which have a much smaller footprint and
run faster:
set someFile to (choose file)
set fullPath to POSIX path of someFile
set basename to do shell script "basename " & quoted form of fullPath
set dirname to do shell script "dirname " & quoted form of fullPath
the basename command has the same optional second argument feature:
set basename to do shell script "basename " & quoted form of fullPath & " .php"
2. Instead of running some other program from the shell, let the shell do it itself with its built-in string magic.
set someFile to (choose file)
set fullPath to POSIX path of someFile
set basename to do shell script "f=" & quoted form of fullPath & "; echo \"${f##*/}\""
set dirname to do shell script "f=" & quoted form of fullPath & "; echo \"${f%/*}\""
To get the suffix removal:
set basename to do shell script "f=" & quoted form of fullPath & "; f=\"${f##*/}\"; echo \"${f%.php]\""
This works regardless of the specific suffix:
set basename to do shell script "f=" & quoted form of fullPath & "; f=\"${f##*/}\"; echo \"${f%.*]\""
--