Sometimes you might require to get a list of all the files in a folder, I was thinking how it can be implemented, the solution is to used the WSH interface and write a script in VBScript.
Below is a sample script which will get the list of files on a directory, say c:\windows and save it to the file c:\windows\FileList.txt.
Example usage:
VB.Net Array Basics
Variables in Visual Basic
Strings in VB - Part I
Binary Conversion In VB
VB6 Small Backup Program
Below is a sample script which will get the list of files on a directory, say c:\windows and save it to the file c:\windows\FileList.txt.
Code: VB
On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder
Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Quit
End If
Set NewFile = fso.CreateTextFile(sFolder&"\FileList.txt", True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
NewFile.WriteLine(folderIdx.Name)
Next
NewFile.Close
Example usage:
Code:
lister.vbs "c:\documents and settings"
More VB Articles
VB.Net Array Basics
Variables in Visual Basic
Strings in VB - Part I
Binary Conversion In VB
VB6 Small Backup Program
hanleyhansen, shabbir
likes this


