Re: Looking for a good scripting language.

From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 03/01/05


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)



Relevant Pages

  • Re: "Cannot use parentheses when calling a Sub" runtime error
    ... could be a problem of the default scripting language. ... is valid code according to the rules of JScript, but not for VBScript. ... Since you seem to create a highly dynamic document, ... be possible that sometimes the first -tag is JScript ...
    (microsoft.public.scripting.vbscript)
  • Re: Simple question
    ... I don't generally question a person's choice of scripting language, ... > Well, it doesn't matter if its in JSCript or VBScript, its just becouse I ...
    (microsoft.public.windows.server.scripting)
  • Re: Calling VBScript functions from JScript and vice versa
    ... routines from one scripting language to another. ... where a JScript routine calls vbScript to do the real work ... > Is there any way to call a VBScript function from JScript? ...
    (microsoft.public.scripting.wsh)
  • Audit Policy Scripting?
    ... servers using scripting - Vbscript, Jscript, Perl, etc.. ...
    (microsoft.public.win2000.security)
  • Re: UNIX tr utility written in vbscript
    ... but written in vbscript (or jscript)? ... written in perl but did not locate one written in vbscript/jscript: ... Does it *need* to be VBScript? ... One stone for private consideration, ...
    (microsoft.public.scripting.vbscript)

Loading