PDA

View Full Version : is there a way to write the file names in a folder in a text file?



Commander
08-15-2002, 01:59 PM
i could've done that the slow way, but writing names down for 2000+ files manually is just wrong:)
thankx

PS: i tried to do a search for it, but i didn't know that to search for

Fordy
08-15-2002, 02:49 PM
If you have windows, then you could try this piece of unadulterated evil

Save as ListFiles.wsf and put in the dir you want to list files for....

Run it and it should create FileListing.txt..

I have used with folder of 2000+ files and it seems to cope...even thoug it is slower than using C++ :0


<PACKAGE>
<JOB>
<SCRIPT LANGUAGE="JScript">
//
// RobJFord 22/6/02
// List Files in Currect Folder
//
// Get File system

try{
var oFS = new ActiveXObject("Scripting.FileSystemObject");
}
catch(e){
WScript.Echo("Could not create file system interface");
WScript.Quit(1);
}

// Get Dir & Files

try{
var oThisScript = oFS.GetFile(WScript.ScriptFullName);
var oCurrDir = oThisScript.ParentFolder;
oThisScript = "";
var oFileCol = new Enumerator(oCurrDir.files);
}
catch(e){
WScript.Echo("Could not enumerate files");
WScript.Quit(1);
}

// Create output file and list

try{
var oOutputFile = oFS.OpenTextFile
(oCurrDir + "\\FileListing.txt",2,"TRUE");
oOutputFile.WriteLine("Listing of " + oCurrDir);
oOutputFile.WriteLine(oCurrDir.files.Count + " Files");

for (;!oFileCol.atEnd();oFileCol.moveNext()){
oOutputFile.WriteLine(oFileCol.item());
}

WScript.Echo("List Made");
oOutputFile.Close();
}
catch(e){
WScript.Echo("Could not list files");
WScript.Quit(1);
}
oOutputFile = "";
oFS = "";
oFileCol = "";
</SCRIPT>
</JOB>
</PACKAGE>

Commander
08-15-2002, 05:11 PM
thankx guys, that really helped out. i really appreciate it.