CheckPath()
CheckPath()
since there is a CheckFilename(), it would be cool to have a CheckPath() aswell.
c ya,
nco2k
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
im talking about a command, to check if the specified path$ contains invalid characters. the counterpart to -> CheckFileName(). i should have called it CheckPathName() or something like that, from the start.
c ya,
nco2k

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
Hi,
As long as this feature isn't available in PureBasic, you could use this little function.
Best regards
Wolf
PS: Feel free to enhance it if you need.
As long as this feature isn't available in PureBasic, you could use this little function.
Best regards
Wolf
PS: Feel free to enhance it if you need.
Code: Select all
; Hroudtwolf
; 04/07/2009
; PureBasic 4.x
; Windows, Linux, OS X
Procedure CheckPath ( sPath.s )
Protected idRegEx .i = CreateRegularExpression ( #PB_Any , "^[[:alnum:]]{1,}[:]{1}(\\{1}[äöüÄÖÜ[:alnum:][:space:]&$§!()}{~#.,´'@€]+)*\\?$" )
Protected blResult.i = MatchRegularExpression ( idRegEx , sPath )
FreeRegularExpression ( idRegEx )
ProcedureReturn blResult
EndProcedure
; Good
Debug CheckPath ( "c:\windows\system32" )
Debug CheckPath ( "c:\documents\Ölplattformen in der Nordsee" )
Debug CheckPath ( "c:\documents\Ölplattformen in der Nordsee\Faunaschäden" )
Debug CheckPath ( "c:\documents\test@test" )
; Bad
Debug CheckPath ( "c:\documents\test|test" )
Debug CheckPath ( "c:\documents\your money bag is < than mine" )
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: CheckPath()
At least in windows, what is valid for a file name is also valid for a folder name. And folders are treated as files internally by FAT32 and others. (This is not the same in amiga for example, where you can have a folder with the same exact name as a file located into the same path.)nco2k wrote:since there is a CheckFilename(), it would be cool to have a CheckPath() aswell.
c ya,
nco2k
So then you can easely compose a quite simple function to detect whether a complete path name is valid or not.
Re: CheckPath()
BUT If you use CheckFilename() to test C:\MyCompany\MyProgram\ which IS a valid fully qualified path, you will get a zero result.Psychophanta wrote:At least in windows, what is valid for a file name is also valid for a folder name. And folders are treated as files internally by FAT32 and others. (This is not the same in amiga for example, where you can have a folder with the same exact name as a file located into the same path.)nco2k wrote:since there is a CheckFilename(), it would be cool to have a CheckPath() aswell.
c ya,
nco2k
So then you can easely compose a quite simple function to detect whether a complete path name is valid or not.
This is because \ is NOT a valid character in a file name. Test it with PureBasic 4.40 and see for yourself !
HP Z800 Workstation
CPU : Dual Xeon 5690 3.46GHz
RAM : 96GB RAM ( 8GB x 12 )
PSU : 1100W
GPU : NVIDIA RTX 3050 8GB
STORAGE : 9TB
(4) 2TB Seagate IronWolf Pro HDD
(1) 1TB Samsung 870 EVO SSD
CPU : Dual Xeon 5690 3.46GHz
RAM : 96GB RAM ( 8GB x 12 )
PSU : 1100W
GPU : NVIDIA RTX 3050 8GB
STORAGE : 9TB
(4) 2TB Seagate IronWolf Pro HDD
(1) 1TB Samsung 870 EVO SSD
Re: CheckPath()
Here's something I knocked out real quick. Seems to work perfectly. Anybody who tests this let me know
if you get correct results or not by replying. If you find a valid path that returns as invalid or an invalid
path that returns as valid !
if you get correct results or not by replying. If you find a valid path that returns as invalid or an invalid
path that returns as valid !
Code: Select all
Enabledebugger
Procedure.l CheckPathName(in.s)
index = 1
lOut.l = #True
Drive$ = StringField(in,index,"\")
p = FindString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",UCase(Left(in,1)),1)
If p <> 0 And Len(in)>2 And Mid(in,2,2) = ":\"
x$ = Drive$ + "\"
Repeat
index + 1
folder$ = StringField(in,index,"\")
If folder$ <> ""
r = CheckFilename(folder$)
If r = 0
lOut.l = #False
EndIf
EndIf
Until folder$=""
Else
lOut.l = #False
EndIf
ProcedureReturn lOut.l
EndProcedure
Procedure IsPathNameOk(path.s)
r = CheckPathName(path)
Select r
Case #False
Debug "INVALID"
Case #True
Debug "VALID"
EndSelect
ProcedureReturn
EndProcedure
;Test Code
path.s = "C:\Program Files\My_Company\My Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\Program Files\My_Company\{My.Application}\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\Program Files\My_Company\My_Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\Program Files\My_Company\My?Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\|rogram Files\My_Company\My*Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\Program Files\My_Company\My|Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\Program Files\My_Company\My<Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\Program Files\My_Company\My>Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
path.s = "C:\Program Files\My_Company\My" + Chr(34) + "Application\"
Debug path.s
IsPathNameOk(path.s)
Debug "==================================="
HP Z800 Workstation
CPU : Dual Xeon 5690 3.46GHz
RAM : 96GB RAM ( 8GB x 12 )
PSU : 1100W
GPU : NVIDIA RTX 3050 8GB
STORAGE : 9TB
(4) 2TB Seagate IronWolf Pro HDD
(1) 1TB Samsung 870 EVO SSD
CPU : Dual Xeon 5690 3.46GHz
RAM : 96GB RAM ( 8GB x 12 )
PSU : 1100W
GPU : NVIDIA RTX 3050 8GB
STORAGE : 9TB
(4) 2TB Seagate IronWolf Pro HDD
(1) 1TB Samsung 870 EVO SSD
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: CheckPath()
Shouldn't "c:" be valid?Mohawk70 wrote:If you find a valid path that returns as invalid or an invalid
path that returns as valid !
And also relative paths like:
"\..", "\.", "..", "."
:roll: