Mzigaib Posted December 4, 2018 Share Posted December 4, 2018 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. Quote Link to comment Share on other sites More sharing options...
Mzigaib Posted December 4, 2018 Author Share Posted December 4, 2018 (edited) 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 December 4, 2018 by Mzigaib Quote Link to comment Share on other sites More sharing options...
toadstorm Posted December 4, 2018 Share Posted December 4, 2018 Is there a reason this needs to be HScript? In Python: import os msg = "Not Found" if os.path.exists(path): msg = "Found" return msg 1 Quote Link to comment Share on other sites More sharing options...
hall Posted December 4, 2018 Share Posted December 4, 2018 I guess the best method is to use python. import os print(os.path.isdir('/dir/path/')) Quote Link to comment Share on other sites More sharing options...
Mzigaib Posted December 4, 2018 Author Share Posted December 4, 2018 4 hours ago, toadstorm said: Is there a reason this needs to be HScript? In Python: import os msg = "Not Found" if os.path.exists(path): msg = "Found" return msg Yes I don't use phyton, but thanks anyway. Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted December 4, 2018 Share Posted December 4, 2018 Extended it a bit: import os node = hou.pwd() dir = node.parm('directory').eval() msg = 'Directory {} does not exist'.format(dir) if os.path.exists(dir): msg = 'Directory {} exists.'.format(dir) elif not dir: msg = 'Choose a directory.' print msg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.