Solved

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

Posted on 2011-03-03
5
513 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:lasthope
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
Comment Utility
Hi,

Please try the following code, it will list the paths of all folders and sub folders recursively. Mention the sub folder to be skipped(pass over) in lower case.
objStartFolder = "C:\backup" 'Mention the source folder path

On Error Resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")


Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path

Wscript.Echo

ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
    If LCase(Subfolder.Name)<> "pass over" Then
        Wscript.Echo Subfolder.Path
        ShowSubFolders Subfolder
    End if    
    Next
End Sub

Open in new window

0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
0
 
LVL 12

Expert Comment

by:prashanthd
Comment Utility
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
0
 

Author Closing Comment

by:lasthope
Comment Utility
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!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now