Jump to content

Check if directory exists with hscript


Mzigaib

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'
    else
        set txt = 'all'
end
message $txt

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

 

Thanks.

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'
    else 
        set check = 'Found'
    endif
end
message $check

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

Thanks.

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.

Guest
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...