set p to "/Users/myAccount/Desktop/testfilename.txt"
set a to POSIX file p
I would like to extract "testfilename.txt" from the posix path above? Anyone know how to go about to do that?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityset p to "/Users/myAccount/Desktop/testfilename.txt"
set a to POSIX file p
I would like to extract "testfilename.txt" from the posix path above? Anyone know how to go about to do that?
Try this:
set yourpath to ("/YOUR/PATH/HERE/file.ext") as POSIX file
do shell script "basename " & quoted form of POSIX path of yourpath
This should work for files and folders as well.
I used "basename " & quoted form of
... because AppleScript and shell script handle spaces in directories quite in a different way, that should allow you to use also paths with spaces in it.
set a to do shell script "basename $HOME/Desktop/testfilename.txt" as string
– user3439894 Mar 21 '16 at 18:27