show only the file-name in tableview

How can i edit this part of my script so that only show the file-name from the dropped file in the table-view. Not the complete path!
Many thanks for your help!

on parse_items(dropped_items, file_types, file_extensions, with_subfolders)
	set valid_items to {}
	repeat with This_Item in dropped_items
		try
			set This_Item to (contents of This_Item as string)
			set This_Item to (((This_Item as POSIX file) as alias) as string)
			set the_info to info for (This_Item as alias)
			
			set is_folder to folder of the_info
			tell application "Finder" to set this_item_type to file type of the_info
			set this_item_extension to name extension of the_info
			
			if file_types contains this_item_type or file_extensions contains this_item_extension then set end of valid_items to This_Item
			if is_folder then
				if with_subfolders then set valid_items to valid_items & (my parse_items((my list_folder(This_Item)), file_types, file_extensions, with_subfolders))
			end if
		on error the_error
			my update_status(the_error)
		end try
	end repeat
	return valid_items
end parse_items

Does nobody can help me?

I’ve used this before, but my paths were in /unix/path/style, not Finder:style:paths. I don’t know if it works on both (I think you are using unix paths).

set this_FileName to call method "lastPathComponent" of This_Item

If it doesn’t work, try getting the POSIX path of the file and working on that path.


Edit:
Oops, forgot to add that many times the result of a “call method something” needs to be returned to a variable. When you do a “call method” you are actually accessing the Cocoa side of Mac OS X, and things work a little differently, so you need to create something (of the write type) to hold that result from a “call method”. So you might have to first do a

set this_FileName to "" -- possibly set this_FileName to {} , it's been a while. 

Note: that if you are just displaying the variable somewhere and aren’t actively using the file name, you can skip creating the variable holder:

set content of text field "status" of progressPanel to "Tagging mp3: " & (call method "lastPathComponent" of mFileName)

works just fine.


And if you want to get the folders involved, this is what I used in an old program of mine:

set base_volume to {}
	set base_volume to (call method "pathComponents" of this_file)
	if (item 2 of base_volume contains "Volumes") then
		set temp_filepath to "/Volumes/" & (item 3 of base_volume) & "/Temporary Items/" & this_new_filename
	else
		set temp_filepath to "/tmp/" & this_new_filename
	end if

Presumably, the parent folder of any file would be something like:

set parent_folder to (item -1 of base_volume) -- could be -2 for all I know, I'm rusty 

Hope that helps somewhat. It’s along those lines, but I forget. Screws fall out all over the place, ya know.

Hi,

Im prety new to applescript, and i had the same question yesterday. After surfing the web i found another way then anaxamander explained.

im sure there is a lot to optimize, but it does the job for me :wink:

add this to your code and call the subrutine with the variable that holds the whole path:

to get_last_item(FileName)

set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set itemCount to (count text items of FileName)
set lastItem to the last text item of FileName
if lastItem = "" then
	set itemCount to itemCount - 1 -- bei Pfad zu einem Ordner 
	set isFolder to "1"
else
	set itemCount to itemCount -- bei Pfad zu einer Datei
	set isFolder to "0"
end if
set FileName to ¬
	text item itemCount of FileName

if isFolder = "1" then
	set FileName to FileName -- is Folder
else
	set FileName to FileName -- is File
	
end if

set AppleScript's text item delimiters to oldDelims
return FileName

end get_last_item

hope this helps,

gustavo