Skip to content

Instantly share code, notes, and snippets.

@romgrk
Last active July 13, 2017 13:59
Show Gist options
  • Select an option

  • Save romgrk/56a3da789a28064f5b01e035fe4634a5 to your computer and use it in GitHub Desktop.

Select an option

Save romgrk/56a3da789a28064f5b01e035fe4634a5 to your computer and use it in GitHub Desktop.
var path = get('global.workPath')
var files = listFiles(path + '/') // Be sure the path ends with '/'
log(files.length)
/*
* Helpers
*/
function get(name) { return typeof name === 'number' ? Watch.getJobInfo(name) : Watch.getVariable(name) }
function set(name, value) { typeof name === 'number' ? Watch.setJobInfo(name, value) : Watch.setVariable(name, value) }
function log(msg) { try { Watch.log(toString(msg), 2) } catch(e) { WScript.stdout.WriteLine(toString(msg)) } }
function err(msg) { try { Watch.log(toString(msg), 1) } catch(e) { WScript.stdout.WriteLine(toString(msg)) } }
function exp(string) { return Watch.expandString(string); }
function xml(string) { return Watch.expandString("xmlget('/request[1]/values[1]/" + string + "[1]',Value,KeepCase,No Trim)"); }
function toString(value) { try { return JSON.stringify(value) } catch(e) { return ''+value } }
function listFolders(path) {
var fs = new ActiveXObject("Scripting.FileSystemObject")
var fc = new Enumerator(fs.GetFolder(path).SubFolders)
var list = []
for (; !fc.atEnd(); fc.moveNext()) {
list.push(fc.item())
}
return list
}
function listFiles(path) {
var fs = new ActiveXObject("Scripting.FileSystemObject")
var fc = new Enumerator(fs.GetFolder(path).files)
var list = []
for (; !fc.atEnd(); fc.moveNext()) {
list.push(fc.item())
}
return list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment