applescript - extract filename from posix path 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?
Try this:

set yourpath to ("/YOUR/PATH/HERE/file.ext") as POSIX file
do shell script "basename " &amp; quoted form of POSIX path of yourpath


This should work for files and folders as well. 
I used "basename " &amp; 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.