











CompTIA
Exam Vouchers
Save money on CompTIA exams
| Question of the day
Sign up to receive
interactive practice questions
for MCSE, CompTIA
Cisco and other exams
| TestKing
Get MCSE, MCSD, CCNA, CCNP,A+, N+ and many more | * ExamSheets *
Guide for Success!
Actual Questions & Answers
MCSE, MCSD, A+ ,CCNA, CCNP
Oracle 8i, Oracle 9i Online practice tests
Certification sites Online university Online college Online education Distance learning Software forum Server administration forum Programming resources
|
|  |
mindmesh
Spit Fire M

Registered: Aug 2002 Location: Philadelphia Country: United States State: Certifications: A+, MCP, MCSA +S, MCSE Working on: CCNA, LPI, RHCE
Total Posts: 1623
|
|
VbScript Question
This script only enumerates the files in a specified folder, how do I get it to enumerate thru all folders and output the files? Thanks.
Option Explicit
On Error Resume Next
Dim folder
folder = Inputbox("Which drive do you want to check?")
getFolder(folder)
Function getFolder(root)
Dim fso, folders, folder, file, files, txtFile
Const Appending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(root) Then
Set txtFile = fso.createtextfile("C:\Owners.txt", False)
If err.number <> 0 then
Set txtFile = fso.opentextfile("C:\Owners.txt", Appending)
End If
txtFile.WriteLine root & "," & getOwner(root)
For Each file In fso.GetFolder(root).Files
txtFile.WriteLine file & "," & getOwner(fso.GetAbsolutePathName(file))
Next
For Each folder In fso.getFolder(root).SubFolders
getFolder(fso.GetAbsolutePathName(folder))
Next
Else
WScript.Echo "Folder doesn't exist: " & root
Exit Function
End If
End Function
Function getOwner(object)
Dim su, sd
Set su = CreateObject("ADsSecurityUtility")
Set sd = su.GetSecurityDescriptor(object, 1, 1)
getOwner = sd.Owner
End Function
Attachment: new text document.txt
This has been downloaded 1 time(s).
__________________
I take no responsibility for the offensive nature of this post.. If you take offense I am sorry, but honestly don't give a damn. All rights reserved!!
Report this post to a moderator
|
|
03-03-05 07:42 PM
|
|
dmaftei
Senior Member M
Registered: Nov 2000 Location: Country: USA State: Certifications: none Working on: none
Total Posts: 2156
|
|
code:
Option Explicit
'' On Error Resume Next; don't ignore errors
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim start
start = fso.GetAbsolutePathName(".") '' or prompt for path
list(start)
'' Recursively list directory contents
Sub list(dirname)
Dim crt
Set crt = fso.GetFolder(dirname)
Dim file
For Each file In crt.Files
wscript.Echo fso.GetAbsolutePathName(file)
Next
Dim subdir
For Each subdir In crt.SubFolders
list(subdir.Name)
Next
End Sub
Last edited by dmaftei on 03-03-05 at 11:11 PM
Report this post to a moderator
|
|
03-03-05 10:11 PM
|
|
mindmesh
Spit Fire M

Registered: Aug 2002 Location: Philadelphia Country: United States State: Certifications: A+, MCP, MCSA +S, MCSE Working on: CCNA, LPI, RHCE
Total Posts: 1623
|
|
Well that sort of works. If I point it to my s:\ it gives me all the files directly in the S:\ but doesn't give me the file that are in the subdriectories of the S: drive. If I point it to "." it goes thru all the files directly in my profile, but not thru all the other folders.
Here's what I'm trying to accomplish, and maybe you can point me in the right direction if you're not sure how to script this. I've stumped quite a few people, and I'm sort of new to VBScript so imagine the headaches.
Two people were recently fired for 'suspicious activity' they want a list of all the files that belong to them on a specific network drive (they want to be able to select which drive each time). I need to have a script that runs thru all the folders on the network drive and gives me the file path and owner of each file. That's where I'm stuck. I can't get it to run thru all the folders and give me all the files and their owners.
Thanks for your help.
__________________
I take no responsibility for the offensive nature of this post.. If you take offense I am sorry, but honestly don't give a damn. All rights reserved!!
Report this post to a moderator
|
|
03-03-05 11:37 PM
|
|
dmaftei
Senior Member M
Registered: Nov 2000 Location: Country: USA State: Certifications: none Working on: none
Total Posts: 2156
|
|
code:
Option Explicit
'' On Error Resume Next '' don't ignore errors
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim drive
Set drive = fso.GetDrive("z") '' replace this with an input box
Dim root
Set root = drive.RootFolder
list(root)
'' Recursively list directory contents
Sub list(dir)
Dim file
For Each file In dir.Files
wscript.Echo file.Path '' add your owner function here
Next
Dim subdir
For Each subdir In dir.SubFolders
list(subdir)
Next
End Sub
Report this post to a moderator
|
|
03-04-05 12:28 AM
|
|
mindmesh
Spit Fire M

Registered: Aug 2002 Location: Philadelphia Country: United States State: Certifications: A+, MCP, MCSA +S, MCSE Working on: CCNA, LPI, RHCE
Total Posts: 1623
|
|
Thanks, dmaftei. Works like a charm. I have one more question for you. The script quits if it hits a file that it doens't have access too. Any ideas on how to let it keep going and just skip that folder? Thanks again.
__________________
I take no responsibility for the offensive nature of this post.. If you take offense I am sorry, but honestly don't give a damn. All rights reserved!!
Report this post to a moderator
|
|
03-04-05 04:30 PM
|
|
dmaftei
Senior Member M
Registered: Nov 2000 Location: Country: USA State: Certifications: none Working on: none
Total Posts: 2156
|
|
As administrator you _should_ have access to everything. Failing that:
code:
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim drive
Set drive = fso.GetDrive("z") '' replace this with an input box
Dim root
Set root = drive.RootFolder
list(root)
'' Recursively list directory contents
Sub list(dir)
Dim file
For Each file In dir.Files
wscript.Echo file.Path '' add your owner function here
Next
Dim subdir
For Each subdir In dir.SubFolders
On Error Resume Next '' skip if cannot dig in
list(subdir)
Next
End Sub
Last edited by dmaftei on 03-04-05 at 05:34 PM
Report this post to a moderator
|
|
03-04-05 05:31 PM
|
|
mindmesh
Spit Fire M

Registered: Aug 2002 Location: Philadelphia Country: United States State: Certifications: A+, MCP, MCSA +S, MCSE Working on: CCNA, LPI, RHCE
Total Posts: 1623
|
|
I'm a Domain Admin.. Maybe the Enterprise admin account.
__________________
I take no responsibility for the offensive nature of this post.. If you take offense I am sorry, but honestly don't give a damn. All rights reserved!!
Report this post to a moderator
|
|
03-04-05 05:42 PM
|
|
|
Featured site: MCSE, MCSD, CompTIA, CCNA training videos
Forum Rules: Who Can Read The Forum? Any registered user or guest.
Who Can Post New Topics? Any registered user.
Who Can Post Replies? Any registered user.
Changes: Messages can be edited by their author.
Posts: HTML code is OFF. Smilies are ON. vB code is ON. [IMG] code is OFF. |
|
ExamNotes forum archive
|