Created
August 21, 2013 10:42
-
-
Save hmasato/6292933 to your computer and use it in GitHub Desktop.
[Softimage, Javascript, Win] _dir.js (x10 ~ faster than GetFolder/SubFolders/Files)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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