Solved

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

Posted on 2011-03-03
5
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
prashanthd earned 500 total points
ID: 35034039
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 55

Expert Comment

by:Bill Prew
ID: 35035846
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 55

Expert Comment

by:Bill Prew
ID: 35037486
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
ID: 35041552
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
ID: 35041732
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Learn about cloud computing and its benefits for small business owners.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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