Solved

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

Posted on 2011-03-03
5
516 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
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 53

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 53

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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