Computing.Net > Forums > Programming > VBScript Help - Retrieving Extended File Prop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBScript Help - Retrieving Extended File Prop

Reply to Message Icon

Name: Owbon
Date: November 5, 2009 at 02:12:42 Pacific
OS: Windows XP
Subcategory: General
Tags: vbscript, File properties, Sub folders
Comment:

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
 



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: November 5, 2009 at 03:34:37 Pacific
Reply:

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.


0

Response Number 2
Name: Owbon
Date: November 5, 2009 at 03:51:46 Pacific
Reply:

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 


0

Response Number 3
Name: klint
Date: November 5, 2009 at 04:28:58 Pacific
Reply:

Shouldn't ListFolderFiles take the current folder as an argument?


0

Response Number 4
Name: Owbon
Date: November 5, 2009 at 05:26:56 Pacific
Reply:

You mean change

Set objFolder = objShell.Namespace(target_Folder)

to
Set objFolder = objShell.Namespace(Folder)

Or run it as

ListFolderFiles(Folder)

??

0

Response Number 5
Name: klint
Date: November 5, 2009 at 08:41:34 Pacific
Reply:

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?


0

Related Posts

See More



Response Number 6
Name: nbrane
Date: November 5, 2009 at 17:04:12 Pacific
Reply:

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


0

Response Number 7
Name: Owbon
Date: November 6, 2009 at 01:40:12 Pacific
Reply:

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


1

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: VBScript Help - Retrieving Extended File Prop

extended file information under XP www.computing.net/answers/programming/extended-file-information-under-xp/7458.html

VBScript help parsing a text file www.computing.net/answers/programming/vbscript-help-parsing-a-text-file/14327.html

VBScript help creating a log file www.computing.net/answers/programming/vbscript-help-creating-a-log-file-/14414.html