GetFilenameWithoutPath()

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

GetFilenameWithoutPath()

Post by BackupUser »

Code updated for 5.20+. Same as GetFilePart()

Restored from previous forum. Originally posted by WolfgangS.

Hi !
if you use a requester to get the file of your choice you get always the path AND the name. To extract the name out from the whole Path+Name try this procedure ...

MFG
WolfgangS

Code: Select all

FileNameWithExtension.s=""

Procedure.s GetFilenameWithoutPath(PAN$) ; Path And Name
  For i=1 To Len(PAN$)
    If Mid(PAN$,Len(PAN$)-i,1)="\"
      ProcedureReturn(Right(PAN$,i))
    EndIf
  Next
  ProcedureReturn(Right(PAN$,i))
EndProcedure

OpenConsole()
FileNameWithExtension=OpenFileRequester("","","",0)
PrintN("WholePath+Name = "+FileNameWithExtension)

PrintN("Just the Name = "+GetFilenameWithoutPath(FileNameWithExtension))
Delay(50000)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Or you could do this...

OpenConsole()
FileNameWithExtension.s=OpenFileRequester("","","",0)
PrintN("WholePath+Name = "+FileNameWithExtension)
PrintN("Just the Name = "+GetFilePart(FileNameWithExtension))
Delay(50000)




Edited by - paul on 29 June 2002 04:58:30
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by WolfgangS.

DOH !
this is embarrassing ... please don't comment ... :*|
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> OpenConsole()
> FileNameWithExtension=OpenFileRequester("","","",0)
> Printn("WholePath+Name = "+FileNameWithExtension)
> PrintN("Just the Name = "+GetFilenameWithoutPath(FileNameWithExtension))
> Delay(50000)

Another tip: You don't need to open a Console to print information like you have
above... just use the Debug command instead; it saves a lot of typing:

Debug "WholePath+Name = "+FileNameWithExtension
Debug "Just the Name = "+GetFilenameWithoutPath(FileNameWithExtension)


PB - Registered PureBasic Coder

Edited by - PB on 29 June 2002 06:20:06
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

But the debug window is annoying...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
But the debug window is annoying...
What ?!

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
DOH !
this is embarrassing ... please don't comment ... :*|
No problem. Its proves than the PB docs isn't perfect (Ok, ok, everybody already knows it). I will add a link to this command in the OpenFileRequester() doc.

Fred - AlphaSND
Post Reply