Page 1 of 1

GetFilePart

Posted: Fri Jul 18, 2025 12:48 pm
by Piero

Code: Select all

; This (Mac/Linux) bug is very unlikely to happen and cause big problems, but I had to report…
Debug GetFilePart(~"/folder/a\"b") ; result: a
Edit (to be more clear): double quotes are allowed in Mac/Linux file names

Re: GetFilePart

Posted: Fri Jul 18, 2025 1:18 pm
by BarryG
Same result on Windows.

Re: GetFilePart

Posted: Fri Jul 18, 2025 1:36 pm
by jacdelad
Maybe because " is not allowed on windows?

Re: GetFilePart

Posted: Fri Jul 18, 2025 1:40 pm
by Axolotl
AFAIK the #DoubleQuote is not a vaild character in a filename, on windows, / and \ are now treated equally and they are not allowed in a filename, too.

Code: Select all

Debug CheckFilename(~"a\"b") ; result: 0 on windows 

Re: GetFilePart

Posted: Fri Jul 18, 2025 8:31 pm
by Piero
Note (also for future reference):
A similar Mac/Linux problem may happen with RunProgram and shell commands, e.g.:

Code: Select all

RunProgram("open", String_With_Single_Or_Double_Quotes ,"")
 
More Info and Fix, also for pipes ( | ):
 
viewtopic.php?p=640177#p640177
 
viewtopic.php?p=643139#p643139
 

CheckGetFilePart

Posted: Sat Jul 19, 2025 5:09 am
by Piero

Code: Select all

; Workaround for GetFilePart bug
Procedure.s CheckGetFilePart(p$,ne=#PB_FileSystem_NoExtension)
   Protected pp$ = GetPathPart(p$), fp$ = GetFilePart(p$)
   If StringByteLength(pp$+fp$) <> StringByteLength(p$)
      ProcedureReturn ""
   EndIf
   ProcedureReturn GetFilePart(p$,ne)
EndProcedure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

s.s= CheckGetFilePart(~"/folder/a\"b")
Debug "Result: "+ s

s= CheckGetFilePart("/folder/ab.txt", 0)
Debug "Result: "+ s

s= CheckGetFilePart("ab.txt")
Debug "Result: "+ s

Re: GetFilePart

Posted: Mon Jul 21, 2025 2:10 pm
by collectordave
Debug GetFilePart(~"/folder/a/b")


Works on MAC

Re: GetFilePart

Posted: Mon Jul 21, 2025 2:35 pm
by Piero
collectordave wrote: Mon Jul 21, 2025 2:10 pm Debug GetFilePart(~"/folder/a/b")
Works on MAC
You don't need ~ for "/folder/a/b", but you need it for ~"/folder/a\"b" (~" \" " is to put a double quote into a string)