GetFilePart

Just starting out? Need help? Post your questions and find answers here.
User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

GetFilePart

Post 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
Last edited by Piero on Fri Jul 18, 2025 3:13 pm, edited 2 times in total.
BarryG
Addict
Addict
Posts: 4118
Joined: Thu Apr 18, 2019 8:17 am

Re: GetFilePart

Post by BarryG »

Same result on Windows.
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: GetFilePart

Post by jacdelad »

Maybe because " is not allowed on windows?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Axolotl
Enthusiast
Enthusiast
Posts: 797
Joined: Wed Dec 31, 2008 3:36 pm

Re: GetFilePart

Post 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 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: GetFilePart

Post 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
 
User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

CheckGetFilePart

Post 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
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: GetFilePart

Post by collectordave »

Debug GetFilePart(~"/folder/a/b")


Works on MAC
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: GetFilePart

Post 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)
Post Reply