Page 1 of 1
How to know if a directory or Path is valid?
Posted: Sun Apr 14, 2019 4:12 pm
by Pierre55
Hi,
If a user enter an invalid path for saving a file my script ends with this error:
http://pages.infinit.net/pgx/ERROR.jpg
so is there a way to make sure the path is correct?
Thank you.
Pierre
Re: How to know if a directory or Path is valid?
Posted: Mon Apr 15, 2019 2:05 pm
by bitRocky
Have a look at this
https://www.hollywood-mal.com/docs/html ... dling.html.
It doesn't helps you to check if the path is correct, but if the functions fails the script won't abort!
You can check the error yourself and message the user to choose a valid path.
Re: How to know if a directory or Path is valid?
Posted: Mon Apr 15, 2019 5:54 pm
by jPV
You can check if the volume is valid with the
HaveVolume() function. And if you then need to check for a deeper directory structure, you can use the
Exists() function.
Re: How to know if a directory or Path is valid?
Posted: Mon Apr 15, 2019 6:28 pm
by jPV
If it's OK to get the "Please insert volume..." requester for wrong volume names (and give a user a possibility to mount/insert the requested device), just check the path with the
Exists() function, and forget the
HaveVolume() function.
But if you want it to quietly check if both volume and path are valid, you could do a simple function like this (quickly pulled together, might not be optimal, and works only on Amiga compatibles in this form):
Code: Select all
Function p_IsValidPath(path$)
Local volume$ = PatternFindStrShort(path$, "(.+:)")
Return(HaveVolume(volume$) And Exists(path$))
EndFunction
Re: How to know if a directory or Path is valid?
Posted: Tue Apr 16, 2019 2:26 am
by Pierre55
Thank you... I'll check that this weekend.
Bye!
Pierre.
Re: How to know if a directory or Path is valid?
Posted: Thu Apr 18, 2019 1:06 pm
by Pierre55
Hi,
The command
HaveVolume() work perfectly in my script:
PathOk = HaveVolume(PathPart(f$))
If PathOk = 0
moai.Request("", "Le chemin ou répertoire n'existe pas!", "OK", "error")
Return
EndIf
Thanks again for your precious help.
Bye!
Pierre