Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List subfolders 1

Status
Not open for further replies.

ccoll23

MIS
Jan 17, 2002
43
0
0
US
Does anyone know how to list the following to a text file?

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
Set colSubfolders = objFolder.Subfolders

For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.Name, objSubfolder.Size
Next

Thanks for any input,

ccoll23
 
not sure what PHV thread says but you can write to a text file or you could cheat and run your script from a cmdline

cscript.exe myscript.vbs > c:\results.txt
 
mrmovie,

Thanks, but how would I write that to file? That's what I'm having trouble with. How would I change the "Wscript.Echo" to write the results to a txt file?

Thanks,

ccoll23

 
how would I write that to file?
This is explained in the link I gave you ...
 
You could do it without using vbscript if you wanted to by doing running this from a command prompt:

c:
cd\FSO
dir *. /B > c:\folderlist.txt


If you want to use vbscript, here is how:

'Set the ForWriting constant for when you open the textfile (you want to write to the text file, not read or append)
Const ForWriting = 2

'Define the output filename here
strOutputFileName = "c:\folderlist.txt"

'Define FSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Create the text file and open it
Set objFile = objFSO.CreateTextFile(strOutputFileName)
Set objFile = Nothing
Set objOutputTxtFile = objFSO.OpenTextFile(strOutputFileName,ForWriting)

'Your existing code get the folder that you want to work with
Set objFolder = objFSO.GetFolder("C:\FSO")
Set colSubfolders = objFolder.Subfolders

For Each objSubfolder in colSubfolders
'Rather than using wscript.echo, you use the write line method
objOutputTxtFile.WriteLine(objSubfolder.Name & "," & objSubfolder.Size)
Next

'Close the text file
objOutputTxtFile.Close

Hope that helps.

 
That's it!!..Thanks benchristian for the help!!!...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top