Description
Simply creates a text file and lists the files within a folder which the user selects. The text file is created in the same location and can be opened on request after the file has been populated.
** Please note, this is a basic script and may cause errors for locations where files cannot be saved to **
Source Code
Dim strPath
strPath = SelectFolder( "" )
If strPath = vbNull Then
WScript.Echo "Cancelled"
Else
Ret = Msgbox("Is this the correct folder? " & vbCrLf & strPath,VBYesNo,"Correct Path?")
If Ret = 6 then
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = strPath
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(strPath & "\List.txt", ForWriting, True)
For Each objFile in colFiles
objTextFile.WriteLine objFile.Name
Next
objTextFile.Close
Else
WScript.Echo "Exiting Now...."
Wscript.Quit
End If
End If
Ret = Msgbox("Do you wish to open the text file now?",VBYesNo,"Open Now?")
If Ret = 6 then
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "notepad.exe " & strPath & "\List.txt"
Set oShell = Nothing
Else
Wscript.Quit
End If
Function SelectFolder( myStartFolder )
Dim objFolder, objItem, objShell
On Error Resume Next
SelectFolder = vbNull
Set objShell = CreateObject( "Shell.Application" )
Set objFolder = objShell.BrowseForFolder( 0, "Select Folder To List Files", 0, myStartFolder )
If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
Set objFolder = Nothing
Set objshell = Nothing
On Error Goto 0
End Function