Link to home
Create AccountLog in
Avatar of lasthope
lasthope

asked on

Want to modify this script so it lists all folders and subfolders.

This script lists all folders/subfolders and permissions.  Now all I want to do is list Folders and Subfolders, with the ability to skip (pass over) a specific folder.  I'm not sure how to change the script to do this.

Thanks in advance!
'    ListACL.vbs
'    ACL Modifications by CyberneticWraith, 2005
'    Changed it to display ACL information for folders
'    Uses "cacls.exe"
'    Run with cscript!
'
'
'    IndexScripts()
'
'
'    Written by Keep Bertha Surfin Heavy Industries,
'    a division of Keep Bertha Surfin Electrical Concern
'    Version 1.0 - KeepBerthaSurfin@Hotmail.com
'

' First thing, check the argument list for a directory.
' If they didn't specify one, use the current directory.

' Run this on the File Server system you desire to get the ACL's from.

' To put this output into a file you just execute "cscript listacl.vbs > acl.txt".



option explicit

' Run the function :)
call IndexScripts


sub IndexScripts()

    dim fso
    set fso = createobject("scripting.filesystemobject")

    dim loc
    if WScript.Arguments.Count = 0 then
        loc = fso.GetAbsolutePathName(".")
    else
        loc = WScript.Arguments(0)
    end if

    GetWorkingFolder loc, 0, 1, "|"

    set fso = nothing
    
End Sub


' called recursively to get a folder to work in
function GetWorkingFolder(foldspec, foldcount, _
                                   firsttime, spacer)

    Dim objShell,oExec
    Set objShell = CreateObject("WScript.Shell")
    
    dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")

    dim fold
    set fold = fso.GetFolder(foldspec)
    
    dim foldcol
    set foldcol = fold.SubFolders
    
    'do the first folder stuff
    if firsttime = 1 then
        wscript.echo fold.path
        
        foldcount = foldcol.count
        firsttime = 0
    end if
    
    dim remaincount
    remaincount = foldcol.count
    
    'do the subfolder stuff
    dim sf
    for each sf in foldcol
                
        'execute cacls to display ACL information
        
        If LCase(sf.Name)<> "pass over" Then
        
        Set oExec = _
          objShell.Exec("cacls " & chr(34) & sf.path & chr(34))
        
        Do While Not oExec.StdOut.AtEndOfStream
             str = oExec.StdOut.ReadAll
             Dim str
             Wscript.StdOut.WriteLine str
        Loop
        
        set oExec = nothing
        
        remaincount = GetWorkingFolder (foldspec +"\"+sf.name, _
                                   remaincount, firsttime, spacer)
    	End if
    next 
    
    'clean up
    set fso = nothing
    
    GetWorkingFolder = foldcount - 1

end function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Bill Prew
Bill Prew

When you hit a folder to be skipped over, do you want to skip just that folder, and still process any of it's subfolders, or skip that whole branch of the tree from that point down?

~bp
It also looked like you had actually added logic to accomplish this to your script with the line:

       If LCase(sf.Name)<> "pass over" Then

What wasn't working the way you wanted it to about that change?

~bp
Modified the code provided by you, it will list the paths of folders and sub folders excluding "pass over". You can use cscript file.vbs > output.txt

Option explicit

' Run the function :)
call IndexScripts

Sub IndexScripts()

    dim fso
    set fso = createobject("scripting.filesystemobject")

    dim loc
    if WScript.Arguments.Count = 0 then
        loc = fso.GetAbsolutePathName(".")
    else
        loc = WScript.Arguments(0)
    end if

    GetWorkingFolder loc, 0, 1, "|"
    set fso = Nothing
   
End Sub

' called recursively to get a folder to work in
function GetWorkingFolder(foldspec, foldcount, _
                                   firsttime, spacer)

    Dim objShell,oExec
    Set objShell = CreateObject("WScript.Shell")
   
    dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")

    dim fold
    set fold = fso.GetFolder(foldspec)
   
    dim foldcol
    set foldcol = fold.SubFolders
   
    'do the first folder stuff
    if firsttime = 1 then
        wscript.echo fold.path
       
        foldcount = foldcol.count
        firsttime = 0
    end if
   
    dim remaincount
    remaincount = foldcol.count
   
    'do the subfolder stuff
    dim sf
    for each sf in foldcol

        If LCase(sf.Name)<> "pass over" Then
       
              WScript.Echo sf.Path
       
              remaincount = GetWorkingFolder (foldspec +"\"+sf.name, _
                                   remaincount, firsttime, spacer)
          End if
    next
   
    'clean up
    set fso = nothing
   
    GetWorkingFolder = foldcount - 1

end function
Avatar of lasthope

ASKER

PRASHANTHD - Both scripts you provided worked perfectly!!

This one is shorter in code and runs much quicker, but it's nice to have the modification to my original script.

Again, absolutely perfect!