Mzigaib 18 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. Share this post Link to post Share on other sites
Mzigaib 18 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 Share this post Link to post Share on other sites
toadstorm 171 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 Share this post Link to post Share on other sites
Hickstein 8 Posted December 4, 2018 I guess the best method is to use python. import os print(os.path.isdir('/dir/path/')) Share this post Link to post Share on other sites
Mzigaib 18 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. Share this post Link to post Share on other sites
konstantin magnus 234 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 Share this post Link to post Share on other sites