Re: Concatenate Files in VBS or JS Windows Scripting
From: Bantu (bantu_at_bantu.com)
Date: 03/24/04
- Next message: Lynn: "Re: silent batch file"
- Previous message: Al Dunbar [MS-MVP]: "Re: Scheduled Task"
- In reply to: Torgeir Bakken \(MVP\): "Re: Concatenate Files in VBS or JS Windows Scripting"
- Next in thread: Richard Fink: "Re: Concatenate Files in VBS or JS Windows Scripting"
- Reply: Richard Fink: "Re: Concatenate Files in VBS or JS Windows Scripting"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 24 Mar 2004 08:09:35 -0800
Thanks for your reply Torgeir. The VBscript code does definitely work.
However, at this time I have put a lot more effort in my Jscript code
already. As that code also loops thru any subfolders in the main
folders and concatenate files in there as well. Also, I wish to
concatenate only those files (all are text files) whose extension is
cmi. Like i had mentioned, everything works and the code loops thru
subfolders etc. but when I do the check for whether the filename
contains .cmi or not, I get a Microsoft JScript runtime error with code:
800A138F and the error is Object expected. What I have done is used
substrings and retrieved just the last three letters of the filename and
compare it to .cmi, however is it not possible to compare 2 string
variables? It seems like it wants me to compare an object or something?
Please let me know if it is possilbe to fix this.
Thanks so much. My code is below.
The error is at the IF and ELSE Statement. The ELSE gives you some kind
of a syntax error and if you remove the ELSE, the IF gives you the
Object expected error. If I take the IF...ELSE out, the code works
perfectly.
// Create File System Object - Needed for working with files through WSH
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
// variable to hold folder and file names
var msg = "";
//var f1 = fso.openTextFile ("A264824.CMI",1); //Open for reading
var newfile = fso.openTextFile ("Jy.txt",2,true); //Open for
writing,create
var newfile2 = fso.openTextFile ("Jy2.txt",2,true);
//newfile.write (f1.ReadAll() );
// call the function scandir - passing it the
// directory where we want to start the scan
scandir( "D:\\TEMP\\TEST1" );
// Function to scan directory
function scandir(dir)
//dir is the variable that contains the folder path and name passed to
the function scandir(dir)
{
// Get Current Folder
var srcFolder = fso.GetFolder(dir);
msg += "Folder: " + srcFolder.Name + "\n";
// Get Files in current directory. Create an enumerator so that we
can move thru the collection.
var files = new Enumerator( srcFolder.files );
// Loop through files
for(; !files.atEnd(); files.moveNext() )
{
// You have access to each file one at a time in an entire
directory tree. Here we grab
// the files name and add to our message variable
newfile.WriteLine(files.item());
var f2 = files.item();
var ItemName = files.item().Name ;
var pos1 = ItemName.lastIndexOf(".");
justTheFileName = ItemName.substring(pos1);
msg += justTheFileName + "\n";
If(justTheFileName ==".cmi")
{
var f3 = fso.openTextFile(f2,1);
newfile2.write (f3.ReadAll() );
}
else
WScript.echo("This is not a CMI file");
}
WScript.echo(msg);
//to display the data gathered in msg.
// Clear the variable for the next directory
msg = "";
// 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() );
scandir( f );
}
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: Lynn: "Re: silent batch file"
- Previous message: Al Dunbar [MS-MVP]: "Re: Scheduled Task"
- In reply to: Torgeir Bakken \(MVP\): "Re: Concatenate Files in VBS or JS Windows Scripting"
- Next in thread: Richard Fink: "Re: Concatenate Files in VBS or JS Windows Scripting"
- Reply: Richard Fink: "Re: Concatenate Files in VBS or JS Windows Scripting"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|