VBScript Help - Retrieving Extended File Prop

November 5, 2009 at 02:12:42
Specs: Windows XP
Hiya

I'm trying to create a script to run on a network drive.
We want to see extended properties of folder and files on the drive but i'm having some issues.

At the moment it just lists the top level folders and files and writes them in to a txt file... I need it to go down it to the sub folders.

I have tried to use Enumaerate Subfolders Using Recursion I.e

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("L:\")

Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        Wscript.Echo Subfolder.Path
        ShowSubFolders Subfolder
    Next
End Sub

But all it does when i add it to my current code is loop the top level...
Any help would be amazing...
This is my code so far!

Dim fsoObject, open_File, target_File, thisday,folder

thisday= Right("0" & Day(Date),2) & "-" & Right("0" & Month(Date),2) & "-" & Right(Year(Date),4)


Set fsoObject = CreateObject("Scripting.FileSystemObject")
target_File = "C:\" & thisday & ".txt"

Function Open_My_File()

  If (fsoObject.FileExists(target_File)) Then
    Set open_File = fsoObject.OpenTextFile(target_File, 8)
  Else
    Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
  End If

End Function



Open_My_File()

open_File.WriteLine "*******************************************"
open_File.WriteLine "* List for: " & thisday & ".                   *"
open_File.WriteLine "* Run at: " & time & ".                     *"
open_File.WriteLine "* This file is named: " & thisday & ".txt      *"
open_File.writeline "*******************************************"
open_File.WriteLine " "
open_File.WriteLine " "





Dim arrHeaders(9)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("L:\")
For i = 0 to 9
 arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
 For i = 0 to 9
 open_File.WriteLine arrHeaders(i) _
 & ": " & objFolder.GetDetailsOf(strFileName, i) 
 
 Next
 open_File.WriteLine "Path: " & strFileName.Path
 open_File.WriteLine " "
Next
 


See More: VBScript Help - Retrieving Extended File Prop

Report •


#1
November 5, 2009 at 03:34:37
I can't reproduce your problem here. Your recursive code works fine on my machine. However, I've only tried the recursive code as a standalone application. Perhaps the problem is when you integrate it into your main app. If you show us the code (with ShowSubfolders being called) we may be able to figure it out.

Report •

#2
November 5, 2009 at 03:51:46
Yes ... Sorry ...


Here is the code ...

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder(target_Folder)

Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        ShowSubFolders Subfolder
		
    Next
	ListFolderFiles()
End Sub






Sub ListFolderFiles()

Dim arrHeaders(9)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(target_Folder)
For i = 0 to 9
 arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
 For i = 0 to 9
 open_File.WriteLine arrHeaders(i) _
 & ": " & objFolder.GetDetailsOf(strFileName, i) 
 
 Next
 open_File.WriteLine "Path: " & strFileName.Path
 open_File.WriteLine " "
Next
End Sub 


Report •

#3
November 5, 2009 at 04:28:58
Shouldn't ListFolderFiles take the current folder as an argument?

Report •

Related Solutions

#4
November 5, 2009 at 05:26:56
You mean change

Set objFolder = objShell.Namespace(target_Folder)

to
Set objFolder = objShell.Namespace(Folder)

Or run it as

ListFolderFiles(Folder)

??

Report •

#5
November 5, 2009 at 08:41:34
I assume target_Folder is a constant string that you initialize at the start of your program. If that's the case, ListFolderFiles will always list the same folder, no matter where you are, because you are always listing target_Folder.

If that's not the case, where are you setting target_Folder?


Report •

#6
November 5, 2009 at 17:04:12
this just goes through the tree, like "dir /s" and lists all files. maybe you can adapt/use
it, i'm not sure. i haven't tried it over network drives yet.

dim obNet
dim fso
dim Folder
Dim strDriveLetter, strRemotePath
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
dim fso
dim Folder
Dim strDriveLetter, strRemotePath
strDriveLetter="Q"
strRemotePath="\\remot\c\"
obNet.MapNetworkDrive strDriveLetter, strRemotePath

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'==== set basepath here, be sure it ends with "\"
Path1="Q:\basepath\"
''''''''''''''''''''''''''''''''''''''''''''''''''
Set ws = CreateObject("WScript.Shell")
Set WshEnv = ws.Environment("SYSTEM")
Set obNet = CreateObject("WScript.Network")
Set fso = createobject("Scripting.FileSystemObject")
Set Folder = fso.GetFolder(Path1)

'========= set locn & name of outputfile here
strDirectory="\vbs\"
strFile="testo"
Set oFile = fso.OpenTextFile (strDirectory & strFile, ForAppending, True)

wscript.echo("starting...")
Path=Path1
Foo
Wscript.Quit

Sub Foo
'====== keep going up (ascend the tree)
set x=fso.Getfolder(Path)
for each folder in x.subfolders
g=folder.name
Path=Path&g&"\"
Foo
next

'======== now list the files at this level
for each file in x.files
e=Path&file.name
oFile.WriteLine(e)
'====== if you want to do other ops, such as get extended attrib.s
'======= or open the file for reading/analysis, it would go here...
next

'==== now go backwards (descend in the tree)
qq=0
for i=1 to 1000
p=InStr(qq+1,Path,"\")
if p>0 then hq=qq else i=1001
qq=p
next
Path=left(path,hq)
set y=fso.Getfolder(Path)
end sub


Report •

#7
November 6, 2009 at 01:40:12
Got it working !!!

Dim fsoObject, open_File, target_File, thisday,folder

thisday= Right("0" & Day(Date),2) & "-" & Right("0" & Month(Date),2) & "-" & Right(Year(Date),4)


Set fsoObject = CreateObject("Scripting.FileSystemObject")
target_File = "C:\" & thisday & ".txt"

Function Open_My_File()

  If (fsoObject.FileExists(target_File)) Then
    Set open_File = fsoObject.OpenTextFile(target_File, 8)
  Else
    Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
  End If

End Function



Open_My_File()

open_File.WriteLine "*******************************************"
open_File.WriteLine "* List for: " & thisday & ".                   *"
open_File.WriteLine "* Run at: " & time & ".                     *"
open_File.WriteLine "* This file is named: " & thisday & ".txt      *"
open_File.writeline "*******************************************"
open_File.WriteLine " "
open_File.WriteLine " "





Dim arrHeaders(9)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("L:\")
For i = 0 to 9
 arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
myFunction(objFolder)

function myFunction(itm)
  For Each strFileName in itm.Items
   For i = 0 to 9
   open_File.WriteLine arrHeaders(i) _
   & ": " & objFolder.GetDetailsOf(strFileName, i) 
   
   Next
   open_File.WriteLine "Path: " & strFileName.Path
   open_File.WriteLine " "
   
   if strFileName.IsFolder then
    myFunction(strFileName.GetFolder)
   end if
  Next 
end function


Report •


Ask Question