Hi,
JScript is the best scripting language for Windoze. Closer to Perl and
open standards ECMA script, and more powerful than "kiddie" VBScript.
You can recurse files and folders with both JScript and VBScript but
you'll have to use a built-in COM object called "FileSystemObject". You
can also use Perl with WMI to manipulate remote machines that don't have
Perl installed. Here's an example of recursing folders using JScript.
This program outputs the current user's IE Favorites to a text file.
Note the trawlFolder() function is being called recursively.
Look out for line wrap!
----- start ----- start ----- start -----
// Fav2Text.js
//
// Convert Current User's Favorites to Text
var strOutFile = "d:\\Fav2Text.txt";
var ForReading = 1;
var ForWriting = 2;
var ForAppending = 8;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var oWshShell = new ActiveXObject("WScript.Shell");
var strFavs = oWshShell.SpecialFolders("Favorites");
var objFolder = fso.GetFolder(strFavs);
var arrFileList = new Array();
arrFileList = trawlFolder(objFolder, arrFileList);
var fh = fso.OpenTextFile(strOutFile, ForWriting, true);
for (var i in arrFileList) {
if (!checkExtension(arrFileList[i].Name)) continue;
var oWshUrlShortcut = oWshShell.CreateShortcut(arrFileList[i].Path);
var strLine = stripExtension(arrFileList[i].Name) + "; ";
strLine += oWshUrlShortcut.TargetPath;
fh.WriteLine(strLine);
}
fh.Close();
fso = null;
oWshShell = null;
function trawlFolder(objFolder, arrFileList) {
var eFolderList = new Enumerator(objFolder.SubFolders);
var eFileList = new Enumerator(objFolder.files);
// Iterate *files* in current *folder*
for (; !eFileList.atEnd(); eFileList.moveNext()) {
objFile = eFileList.item();
arrFileList.push(objFile);
}
// Iterate *subfolders* below current *folder*
for (; !eFolderList.atEnd(); eFolderList.moveNext()) {
objFolder = eFolderList.item();
arrFileList = trawlFolder(objFolder, arrFileList);
}
return arrFileList;
}
function stripExtension(strFileName) {
var re = /\..+$/i;
var strName = strFileName.replace(re,"");
return strName;
}
function checkExtension(strFileName) {
var re = /\.url$/i;
if(strFileName.match(re)) {
return true;
} else {
return false;
}
}
----- end ----- end ----- end -----
Post by s***@hotmail.comHello,
I am newbie to Windows. (Advanced Linux user). For Windows, I want
to
write a script that searchs for all executables in computer. Then, I
want to
run another program ("dumpbin") on each of the result. Finally I want
to
collate the results.
Can someone tell me what is a good language to do this? I looked at
VBScript
and Windows Script Host. TO me, it looks like these languages do not
support
directory traversal.
I can use PERL. But then, I do no want to install perl. My program will
have
to run on some hosts which may not have perl. So I want to make
miminalistic
assumptions.
thanks,
Sudhakar.
--
Gerry Hickman (London UK)