billbrasky
Technical User
- May 17, 2012
- 5
I'm a humble guy. I'm far from being a VBScript guru, but I always try to do my own research and solve my own problems. I hardly ever ask people for help, but I've been working on this ONE problem for two solid days now, and I'm rapidly becoming a danger to myself and others. I come to you all because I now surrender. You win, VBScript. It's a pretty short script, but I simply don't understand why it won't work.
This command-line script remotely enumerates all folders (along with some folder properties) within a specified path.
For example, if this script was named myscript.vbs, and you had a remote workstation on your network called Icebox, and it had a local folder with the path of C:\Common, the command-line synax would be:
C:\> myscript.vbs Icebox c:\common
Here's the code:
' Converts arguments from Icebox c:\common to \\icebox\c$\common
strPath = "\\" & WScript.Arguments(0) & "\" & Replace(WScript.Arguments(1),":","$")
' The subroutine below is called
ShowFolderDetails strPath
Sub ShowFolderDetails(strPath)
Set objFSOFolder = CreateObject("Scripting.FileSystemObject").GetFolder(strPath)
Set objShellFolder = CreateObject("Shell.Application").Namespace(strPath)
' The following line indents and prints a preceding \ to the relative path
WScript.Echo Space(UBound(Split(objFSOFolder.Path,"\"))-3) & "\" & _
objFSOFolder.Name & " - " & _
FormatNumber(objFSOFolder.Size/1000,0) & "k" & _
", Owner: " & objShellFolder.GetDetailsOf(objShellFolder.ParseName(objShellFolder.Title),10) & _
", Last Accessed: " & objFSOFolder.DateLastAccessed
' The loop below iterates through each subfolder, this subroutine recursively calls itself as needed
For Each Subfolder in objFSOFolder.Subfolders
ShowFolderDetails Subfolder.Path
Next
End Sub
The problem is with the line in bold. When I manually substitute in a value for objShellFolder.Title (such as "testfolder"), it works fine for that one folder. When I switch it to a variable that I've confirmed contains that same correct string value, it just won't work. It outputs the file's extended property name instead of it's value (it outputs the word "Owner" instead of Icebox\LocalAdmin).
ParseName needs to accept a variable because the script is on a loop and it's the only way to output the data. ParseName simply won't work when it's fed a variable. I've wasted so much time trying to code around it, and I'm coming apart over here. Please help.
Desperately,
Bill
This command-line script remotely enumerates all folders (along with some folder properties) within a specified path.
For example, if this script was named myscript.vbs, and you had a remote workstation on your network called Icebox, and it had a local folder with the path of C:\Common, the command-line synax would be:
C:\> myscript.vbs Icebox c:\common
Here's the code:
' Converts arguments from Icebox c:\common to \\icebox\c$\common
strPath = "\\" & WScript.Arguments(0) & "\" & Replace(WScript.Arguments(1),":","$")
' The subroutine below is called
ShowFolderDetails strPath
Sub ShowFolderDetails(strPath)
Set objFSOFolder = CreateObject("Scripting.FileSystemObject").GetFolder(strPath)
Set objShellFolder = CreateObject("Shell.Application").Namespace(strPath)
' The following line indents and prints a preceding \ to the relative path
WScript.Echo Space(UBound(Split(objFSOFolder.Path,"\"))-3) & "\" & _
objFSOFolder.Name & " - " & _
FormatNumber(objFSOFolder.Size/1000,0) & "k" & _
", Owner: " & objShellFolder.GetDetailsOf(objShellFolder.ParseName(objShellFolder.Title),10) & _
", Last Accessed: " & objFSOFolder.DateLastAccessed
' The loop below iterates through each subfolder, this subroutine recursively calls itself as needed
For Each Subfolder in objFSOFolder.Subfolders
ShowFolderDetails Subfolder.Path
Next
End Sub
The problem is with the line in bold. When I manually substitute in a value for objShellFolder.Title (such as "testfolder"), it works fine for that one folder. When I switch it to a variable that I've confirmed contains that same correct string value, it just won't work. It outputs the file's extended property name instead of it's value (it outputs the word "Owner" instead of Icebox\LocalAdmin).
ParseName needs to accept a variable because the script is on a loop and it's the only way to output the data. ParseName simply won't work when it's fed a variable. I've wasted so much time trying to code around it, and I'm coming apart over here. Please help.
Desperately,
Bill