Jump to content

Check if directory exists with hscript


Recommended Posts

Is there a way to check if a directory exists with hscript? I try this:

set txt=''
foreach dir(`run('uls -p /mnt/non_existente/directory')`)
    if ($dir != "")
        set txt = 'nothing'
        set txt = 'all'
message $txt

But if the directory doesn't exist it return me nothing, any tips?



Link to comment
Share on other sites

I found a way:

# Check if directory exists
set check=''
foreach dir(`system(" if [ -d 'your_directory_path_or_not' ];then echo 'yes';else echo 'not';fi")`)
    if (`strmatch($dir,"not")`==1)
        set check = 'Not Found'
        set check = 'Found'
message $check

But if anyone have a better and more elegant way let me know.


Edited by Mzigaib
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...