Question Validate Path

Greetings Everyone! I am using OpenEdge 11.3.1, My user will specified a path where he/she will save the output file.
My problem Masters is I have to validate the specified path by the user, if the path existing and if its writable, can you help me Masters ? I am looking forward for your responses, Thank you.
 

Stefan

Well-Known Member
This should get you started:
Code:
def var cmy_path as char init "/something/that/does/not/exist".

do on error undo, throw:

   output to value( cmy_path ).

   catch e as progress.lang.error:
      message e:getmessagenum(1) skip e:getmessage(1) view-as alert-box.
   end.
   
   finally:
      output close.      
   end finally.

end.
 

Cringer

ProgressTalk.com Moderator
Staff member
Code:
def var cmy_path as char init "/something/that/does/not/exist".
file-info:file-name = cmy_path.
if file-info:file-type eq ? then /*handle error*/.

Not tested this, but I'm pretty sure the file-info handle will do what you want.
 

Stefan

Well-Known Member
The file-info handle will not tell you if you can actually write to that directory. On my Windows 10 laptop, the file-type on file-info handle for 'c:\program files' reports DRW - but an attempt to actually write will return error 98 since elevated permissions are required.
 

Cringer

ProgressTalk.com Moderator
Staff member
Fair point about the writeable nature of the location. I hadn't seen that part of the requirement. It's a good sanity check though that the path exists. Also, good for checking if a directory or a file has been selected.
 
This should get you started:
Code:
def var cmy_path as char init "/something/that/does/not/exist".

do on error undo, throw:

   output to value( cmy_path ).

   catch e as progress.lang.error:
      message e:getmessagenum(1) skip e:getmessage(1) view-as alert-box.
   end.
  
   finally:
      output close.     
   end finally.

end.

I will try it Master Stefan, Thank you very much.
 
Code:
def var cmy_path as char init "/something/that/does/not/exist".
file-info:file-name = cmy_path.
if file-info:file-type eq ? then /*handle error*/.

Not tested this, but I'm pretty sure the file-info handle will do what you want.

I will try it Master Cringer, Thank you very much.
 
This should get you started:
Code:
def var cmy_path as char init "/something/that/does/not/exist".

do on error undo, throw:

   output to value( cmy_path ).

   catch e as progress.lang.error:
      message e:getmessagenum(1) skip e:getmessage(1) view-as alert-box.
   end.
  
   finally:
      output close.     
   end finally.

end.

Master Stefan, Why It keeps returning the error 98 even if in directory where I can actually write.
 

Stefan

Well-Known Member
You do realize that in your case above that 'exist' is the file that is being written? So if 'exist' is a directory it will fail.
 
Code:
def var cmy_path as char init "/something/that/does/not/exist".
file-info:file-name = cmy_path.
if file-info:file-type eq ? then /*handle error*/.

Not tested this, but I'm pretty sure the file-info handle will do what you want.

Master Cringer I tested your code and it works and it helps me on determining either the path existed or not and if it has a duplicate filename. Thank you very much, but on the other hand my Boss wanted to verify if the user could write in the path specified or not. I still have one problem Master.
 
Write a small test file?
Yes Master TheMadDBA, before the user will save the output file at the directory where he/she specified, my task is to first validate the path, then filter if the filename is existing and lastly if the user's have a permission to write to the directory. I already solved the 1st and 2nd problem Master.
 
Top