lis files in a folder and subfolder

Discussion in 'Scripting' started by Glenn, Sep 15, 2006.

  1. Glenn

    Glenn Guest

    I'm trying to write a script that will list all of the files in a folder and
    its subfolders in an excel file.

    I've had some success. I can get the files in the root folder, but not the
    ones in the sub folders.

    The folder is on a remote computer.

    How can I get a list of what is in the sub folders too?
    Glenn, Sep 15, 2006
    1. Advertisements

  2. Try using a mapped drive to this computer. (You will have to setup a file
    share on that computer.) Be sure you set the permission properly.
    runawayabc123, Sep 20, 2006
    1. Advertisements

  3. Glenn

    IT Staff Guest

    Set FSO = CreateObject("Scripting.FileSystemObject")
    ShowSubfolders FSO.GetFolder("C:\Scripts")
    Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
    Wscript.Echo Subfolder.Path
    ShowSubFolders Subfolder
    End Sub

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colFiles = objWMIService. _
    ExecQuery("Select * from CIM_DataFile where Path = '\\Scripts\\'")
    For Each objFile in colFiles
    Wscript.Echo objFile.Name


    above are 2 sample scripts from technet. Combine together by redo. U shld be
    able to get what u need.

    As for exporting to excel, i usually don't do that as vbscript can use > to
    export to text file, which later can be import into excel
    IT Staff, Oct 9, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.