I went online and found bits and pieces of how to do this, but I'm stuck. What I want is a vbscript that will create a directory tree and write it to a text file.
In this attempt, I got the second part to work. But I don't know what to change "wscript" to in the first part. And there is a bunch I still don't understand in the first part, but if I knew what "wscript" should be, I'd probably be able to get it working.
Code: Select all
VBSTART
'First Part
' Show simple directory tree
Option Explicit
Dim sArg, oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Get folder (default is current directory)
If Wscript.Arguments.Count > 0 Then
sArg = Wscript.Arguments(0)
Else
sArg = "."
End If
sArg = oFSO.GetAbsolutePathName(sArg)
' Process entire tree (if valid folder)
If oFSO.FolderExists(sArg) Then
Wscript.Echo "Folder tree for:", sArg
ShowTree "", oFSO.GetFolder(sArg)
End If
Set oFSO = Nothing
Wscript.Quit(0)
Sub ShowTree(sIndent, oFolder)
Dim oSubFolder, ix
ix = 1
For Each oSubFolder In oFolder.SubFolders
Wscript.Echo sIndent & "+--" & oSubFolder.Name
If ix <> oFolder.SubFolders.Count Then
ShowTree sIndent & "| ", oSubFolder
Else
ShowTree sIndent & " ", oSubFolder
End If
ix = ix + 1
Next
End Sub
'Second Part
Set fso = CreateObject("Scripting.FileSystemObject" )
Set file = fso.OpenTextFile("C:\ListFile.txt",2,1)
strFile = "c:\ListFile2.txt"
strLine = "This is a test."
Set objOutFile = fso.CreateTextFile(strFile,True)
objOutFile.Write(strLine)
VBEND
If you paste the first part into notepad and name it something.vbs, it works, but I wanted to get rid of the messages and write the result to a file.
Thanks for helping.