Skip to content

Instantly share code, notes, and snippets.

@hmasato
Created August 21, 2013 10:42
Show Gist options
  • Select an option

  • Save hmasato/6292933 to your computer and use it in GitHub Desktop.

Select an option

Save hmasato/6292933 to your computer and use it in GitHub Desktop.
[Softimage, Javascript, Win] _dir.js (x10 ~ faster than GetFolder/SubFolders/Files)
function _dos(cmd){
var ret=[];
if(cmd=="") return(ret);
var wsh = XSIFactory.CreateActiveXObject('WScript.Shell');
var tmp = wsh.ExpandEnvironmentStrings("%TEMP%");
var fn = tmp+"\\_log_dos_return.txt";
var er = wsh.Run("cmd /c "+cmd+" > " + fn, 0, true);
if(er) return(ret);
var fs = XSIFactory.CreateObject('Scripting.FileSystemObject');
if(!fs.FileExists(fn)) return(ret);
var f=fs.OpenTextFile(fn);
while(true) try{ ret.push(f.ReadLine()); }catch(e){ f.Close(); break; }
return(ret);
}
function _getFolders(path){
if(path=="") return([]);
return _dos("dir /b /O:N /A:D \""+path+"\"");
}
function _getFiles(path){
if(path=="") return([]);
return _dos("dir /b /O:N /A:-D \""+path+"\"");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment