Page 1 of 1

GetFilenameWithoutPath()

Posted: Sat Jun 29, 2002 1:40 am
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)

Posted: Sat Jun 29, 2002 3:57 am
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

Posted: Sat Jun 29, 2002 4:50 am
by BackupUser
Restored from previous forum. Originally posted by WolfgangS.

DOH !
this is embarrassing ... please don't comment ... :*|

Posted: Sat Jun 29, 2002 5:19 am
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

Posted: Sat Jun 29, 2002 9:25 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

But the debug window is annoying...

Posted: Sun Jun 30, 2002 7:36 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
But the debug window is annoying...
What ?!

Fred - AlphaSND

Posted: Sun Jun 30, 2002 7:37 pm
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