Head and Tail of file path

I’m trying to get the tail end of a path where only the file name exists

Could someone please share what’s the best way to do such a thing?

ex.

/dir/dir/file1.ext
/dir/file2.ext
/dir/dir/dir/dir/dir/file3.txt
/dir/dir/dir/dir/dir/ file3.txt

result:

file1.ext
file2.ext
file3.ext
file3.ext

thanks

If the file reference is of the form alias “YourHD:Users:Documents:MyStuff:file3.txt” as it might be if you had done a “choose file” then

set theFile to choose file  -- returns an alias
tell application "Finder" to set theName to name of theFile -- returns the file name only

If you’ve got a POSIX path (with “/”, instead of “:”), then this works:

set theFile to POSIX path of (choose file)
set {TID, text item delimiters} to {text item delimiters, "/"}
set theName to last text item of theFile
set text item delimiters to TID
theName