How to know if a directory or Path is valid?

Discuss any general programming issues here
Post Reply
Pierre55
Posts: 54
Joined: Sat Apr 01, 2017 4:25 pm

How to know if a directory or Path is valid?

Post 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
bitRocky
Posts: 120
Joined: Fri Nov 14, 2014 6:01 pm

Re: How to know if a directory or Path is valid?

Post 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.
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: How to know if a directory or Path is valid?

Post 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.
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: How to know if a directory or Path is valid?

Post 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
Pierre55
Posts: 54
Joined: Sat Apr 01, 2017 4:25 pm

Re: How to know if a directory or Path is valid?

Post by Pierre55 »

Thank you... I'll check that this weekend.

Bye!

Pierre.
Pierre55
Posts: 54
Joined: Sat Apr 01, 2017 4:25 pm

Re: How to know if a directory or Path is valid?

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