Re: Looking for a good scripting language.
From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 03/01/05
- Next message: Al Dunbar [MS-MVP]: "Re: Deny _WRITE_ access to a file"
- Previous message: Al Dunbar [MS-MVP]: "Re: Deny _WRITE_ access to a file"
- In reply to: Gerry Hickman: "Re: Looking for a good scripting language."
- Next in thread: Torgeir Bakken \(MVP\): "Re: Looking for a good scripting language."
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 28 Feb 2005 21:19:50 -0700
"Gerry Hickman" <gerry666uk@yahoo.co.uk> wrote in message
news:OdC%23W2eHFHA.3196@TK2MSFTNGP15.phx.gbl...
> 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.
Although I agree that jscript is a more powerful scripting language than
batch, the distance between batch and jscript is of a similar order of
magnitude to that between batch and vbscript.
Had the question been asked in one of the batch-oriented newsgroups, a batch
solution would likely have been given that was simpler and more direct than
your jscript one (or its vbscript equivalent!).
Powerful is one thing, applicability to the task is another. Of course, the
OP's original environment and background might have a thing or two to say
about this as well.
/Al
> 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 -----
>
> sudhakarg79@hotmail.com wrote:
>
> > Hello,
> >
> > 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)
- Next message: Al Dunbar [MS-MVP]: "Re: Deny _WRITE_ access to a file"
- Previous message: Al Dunbar [MS-MVP]: "Re: Deny _WRITE_ access to a file"
- In reply to: Gerry Hickman: "Re: Looking for a good scripting language."
- Next in thread: Torgeir Bakken \(MVP\): "Re: Looking for a good scripting language."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|