11-16-2012, 07:56 PM
Hi there,
If you wan to just select a folder from the Browse for folder dialog. Try the code mentioned below. It should work.
' ****** subs below ******
If you wan to just select a folder from the Browse for folder dialog. Try the code mentioned below. It should work.
Code:
Option Explicit
On Error Resume Next
Dim FolderPath 'Path to the folder to be searched for files
Dim objFSO 'The fileSystemObject
Dim objFolder 'The folder object
Dim colFiles 'Collection of files from files method
Dim objFile 'individual file object
Dim strOUT 'Single output variable
subCheckWscript 'Ensures script is running under wscript
subGetFolder 'Calls the browseForFOlder method
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FolderPath)
Set colFiles = objFolder.Files
For Each objFile in colFiles
strOUT = strOUT & objFile.Name & vbTab & objFile.Size _
& " bytes" & VbCrLf
Next
WScript.Echo strOUT
' ****** subs below ******
Code:
Sub subCheckWscript
If UCase(Right(WScript.FullName, 11)) = "CSCRIPT.EXE" Then
WScript.Echo "This script must be run under WScript."
WScript.Quit
End If
End Sub
Sub subGetFolder
Dim objShell, objFOlder, objFolderItem
Const windowHandle = 0
Const folderOnly = 0
const folderAndFiles = &H4000&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(windowHandle, "Select a folder:", folderOnly)
Set objFolderItem = objFolder.Self
FolderPath = objFolderItem.Path
End Sub