Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

first JS script with problems

Status
Not open for further replies.

Blakeseven

Technical User
Nov 17, 2002
21
US
I have a large dir tree I need to work thru. I have set up this script to look in each sub dir and find *.tif files then use a program called tiff junction to turn them into pdf's. the problem I have is striping the "f:\" out of a var so I can build the same dir tree in a different drive. can any one help

Ben



fso = new ActiveXObject( "Scripting.FileSystemObject" );



var startDir = "f:\\";// Hard coded for simplicity

var WshShell = WScript.CreateObject("WScript.Shell");



function main()

{

strip( startDir );



}

main();

function scandir( dir,ben )

{

// Get Current Folder

var srcFolder = fso.GetFolder( dir );


// Get any sub folders to current directory

var esub = new Enumerator( srcFolder.SubFolders );



// Loop through sub folder list and scan

// through a recursive call to this function

for(; !esub.atEnd(); esub.moveNext() )

{



var f = fso.GetFolder( esub.item() );

var srcFolder = fso.GetFolder( dir );

sub= esub.item().Name; // Don't need this : + "\n";

//WScript.Echo ("f="+f);
//var tom=f;
//var ben = tom.substr(3);

cmd='"'+'C:\\Program Files\\Aquaforest\\TIFF Junction\\bin\\tiffjunction.exe'+'"'+' -P -T '+'"'+'f:\\pdf'+ben+'\\'+sub+'.pdf'+'"'+' "'+f+'\\*.tif'+'"';

WScript.Echo(cmd);
WshShell.Run(cmd,1,true);

// WScript.Echo('"'+f+"\00000001.pdf"+'"',"f:\\pdf\\"+sub+".pdf");


strip( f );

}
}
function strip( srt )
{
var ben=srt.substr(3);
scandir (srt,ben);
}
 
The problem is how you use the substr method in your strip function, copied below:

[tt]function strip( srt )
{
var ben=srt.substr(3);
scandir (srt,ben);
}[/tt]

The substr method of the String object has two parameters, start (required) and length (optional). Since you're only using one parameter in your substr call, JS thinks you want to start from the 3rd character in string srt, and since you didn't specify a 2nd parameter, it will return a string from the 3rd character of srt to the end.

This is an easy fix. Change the highlighted line above to as follows:

[tt]var ben = srt.substr(0,3);[/tt]

since you always want to look for the first 3 characters in the string.

A good JS reference to consult on this stuff is from Netscape, found at
Netscape's DevEdge site is a good resource in general for JS, though it is, of course, skewed toward the Netscape browser.

HTH,
jp
 
this var will change once the script works thru all sub dir's. what I need is to have the var with a value of "f:\test\test2\" to be changed to " test\test2\"

The script I created works the first run thru the loop and then errors out.

What have I done Wrong.

Thanks for your earlier.

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top