Dropped file name?

Hi,
I have a canvas in my window which accepts file drops. Can anyone please point me in the right direction how I get the name of the dropped file?
The extension is not necessary - I just need to find out the name of the file so that I can access it later on.

Thank you all in advance.

DragItem allows you to access the dropped object in few different ways, one of which being the FolderItem. You can then use the FolderItem properties to get the information you seek.

In the DropObject event,

dim sName as String = Obj.FolderItem.DisplayName

@Tim Parnell you are faster than I am.

Thanks Tim, I found the answer about a minute before you posted it :slight_smile:
Any ideas how I remove the last 4 characters (the . and the file extension)?

Just point me in the right direction, and I’ll work it out.

I’m rustyer than a rusty wheel in a rusty wheels yard :slight_smile:

Thanks.

http://documentation.xojo.com/index.php/Replace

Thanks Mr Bujardet :slight_smile:

A file extension does not always have 3 characters

Public Function GetFileName(Extends f As folderitem) as String
  dim name as String
  dim parts(), filename() as string 
  parts = f.NativePath.Split( "/" )
  filename = f.NativePath.Split( "." )
  name = parts(UBound(parts)).Replace("." + filename(UBound(filename)), "")
  Return name
End Function

Thanks Axel :slight_smile:

Please use .name to get file name and not mess around with nativepath.
Because there may be other delimiters than a slash.

[quote=301517:@Axel Schneider]A file extension does not always have 3 characters

Public Function GetFileName(Extends f As folderitem) as String dim name as String dim parts(), filename() as string parts = f.NativePath.Split( "/" ) filename = f.NativePath.Split( "." ) name = parts(UBound(parts)).Replace("." + filename(UBound(filename)), "") Return name End Function [/quote]

the problem is if the extension is .MPEG4 and if the application has .MPEG4 in the middle of it, then you will not remove the right .MPEG4.

thanks!

public function FilenameWithoutExtension(extends fItem as FolderItem) as String
  dim arsSplitNameParts() as String = fItem.name.split(".")
  call arsSplitNameParts.pop
  return Join(arsSplitNameParts, ".")
end function

If that works with no modification someone owes me a drink.

try a file named “123” with NO extension :stuck_out_tongue:

it doesn’t consider the case of NO extension at all

damned edge cases

public function FilenameWithoutExtension(extends fItem as FolderItem) as String
  dim arsSplitNameParts() as String = fItem.name.split(".")
  if arsSplitNameParts.uBound() > 0 then
     call arsSplitNameParts.pop
  end if
return Join(arsSplitNameParts, ".")
end function