Results 1 to 2 of 2

Thread: How to give variable folder path in vbscript?

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    2

    How to give variable folder path in vbscript?

    This script basically goes to a folder and list all the files in that folder and output it in a txt file. Now instead of defining the folder path I want it to use the txt file that contains a bunch of folder paths in it and I want to loop that txt file. How can I do this?

    Code:
    Dim fso
    Dim ObjFolder
    Dim ObjOutFile
    Dim ObjFiles
    Dim ObjFile
    
    'Creating File System Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    'Getting the Folder Object
    Set ObjFolder = fso.GetFolder("C:\Users\Susan\Desktop\Anime\ova")
    
    'Creating an Output File to write the File Names
    Set ObjOutFile = fso.CreateTextFile("C:\Users\Susan\Documents\iMacros\Macros\WindowsFiles.txt")
    
    'Getting the list of Files
    Set ObjFiles = ObjFolder.Files
    
    'Writing Name and Path of each File to Output File
    For Each ObjFile In ObjFiles
        ObjOutFile.WriteLine(ObjFile.Path)
    Next
    
    ObjOutFile.Close

  2. #2
    Addicted Member
    Join Date
    Jul 09
    Posts
    208

    Re: How to give variable folder path in vbscript?

    Use FileSystemObject OpenTextFile and ReadLine to loop through the text file, using the folder string read from the file instead of your hard-coded folder name. Put the CreateTextFile before the loop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •