Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-03
5
Medium Priority
?
529 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 2000 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 58

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 58

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

596 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