Thread: is there a way to write the file names in a folder in a text file?

  1. #1
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801

    is there a way to write the file names in a folder in a text file?

    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
    Last edited by Commander; 08-15-2002 at 02:02 PM.
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    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
    Code:
    <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>

  3. #3
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    801
    thankx guys, that really helped out. i really appreciate it.
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: [email protected] []*[]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Removing text between /* */ in a file
    By 0rion in forum C Programming
    Replies: 2
    Last Post: 04-05-2004, 08:54 AM
  4. Write some text to a file
    By Unlimited4s in forum C++ Programming
    Replies: 7
    Last Post: 07-17-2002, 03:37 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM