![]() |
List All Files in Folder using VBScript
On 24th June, 2006
|
Recent Articles
Similar Articles
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
Example usage: Code:
lister.vbs "c:\documents and settings" |
|
|
#2 |
|
Newbie Member
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: List All Files in Folder using VBScript
hi, very nice a wonderful example code htl. |
|
|
|
|
|
#3 | |
|
Newbie Member
Join Date: Jan 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: List All Files in Folder using VBScript
Hey, i would like to enchance it by providing a dialog box. However, i failed to make it work. Care to point me on the right direction? Quote:
|
|
|
|
|
|
|
#4 |
|
Newbie Member
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: List All Files in Folder using VBScriptCode:
On Error Resume Next
Const WINDOW_HANDLE = 0
Const BIF_EDITBOX = &H10
Const BIF_NONEWFOLDER = &H0200
Const BIF_RETURNONLYFSDIRS = &H1
Set objShell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'**Browse For Folder To Be Processed
strPrompt = "Please select the folder to process."
intOptions = BIF_RETURNONLYFSDIRS + BIF_NONEWFOLDER + BIF_EDITBOX
strTargetPath = wshShell.SpecialFolders("MyDocuments")
strFolderPath = Browse4Folder(strPrompt, intOptions, strTargetPath)
Set objNewFile = objFSO.CreateTextFile(strFolderPath & "\filelist.txt", True)
Set objFolder = objFSO.GetFolder(strFolderPath)
Set objColFiles = objFolder.Files
For Each file In objColFiles
objNewFile.WriteLine(file.Name)
Next
objNewFile.Close
'**Browse4Folder Function
Function Browse4Folder(strPrompt, intOptions, strRoot)
Dim objFolder, objFolderItem
On Error Resume Next
Set objFolder = objShell.BrowseForFolder(0, strPrompt, intOptions, strRoot)
If (objFolder Is Nothing) Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
Browse4Folder = objFolderItem.Path
Set objFolderItem = Nothing
Set objFolder = Nothing
End Function
Last edited by shabbir; 01-30-2009 at 10:58 PM. Reason: Code block |
|
|
|
|
|
#5 |
|
Newbie Member
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: List All Files in Folder using VBScript
So how could you modify this to list all sub directories inside the folder you choose?
|
|
|
|
|
|
#6 | |
|
~ Б0ЯИ Τ0 С0δЭ ~
![]() |
Re: List All Files in Folder using VBScriptQuote:
Code: vb
__________________
My articles --=|=-- Download G4EF Toolbar for Firefox --=|=-- Report G4EF Toolbar Bugs
There are times when sorrow seems the only truth. |
|
|
|
|
|
|
#7 |
|
Newbie Member
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: List All Files in Folder using VBScript
HI hi, very nice a wonderful example code and i thank u really great......... Staffing service Seo master |
|
|
|
|
|
#8 |
|
~ Б0ЯИ Τ0 С0δЭ ~
![]() |
Re: List All Files in Folder using VBScript
You are welcome !
__________________
My articles --=|=-- Download G4EF Toolbar for Firefox --=|=-- Report G4EF Toolbar Bugs
There are times when sorrow seems the only truth. |
|
|
|
|
|
#9 |
|
Newbie Member
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: List All Files in Folder using VBScript
This is definitley a great example. How can it be modified to list files in the main directory and any subdirectories? I'd like to write something that will give me the name, create date, modify date for all files in the main directory and for any files in the sub-directories. I wrote the following, but it can not handle sub-directories. Any help is appreciated. Thanks. On Error Resume Next Dim fso, folder, files, NewsFile,sFolder Set fso = CreateObject("Scripting.FileSystemObject") Set folder = fso.GetFolder("C:\Documents and Settings\Phat Buddha\desktop\") Set outfile = fso.CreateTextFile("c:\temp\testout.txt") Set files = folder.Files For each folderIdx In files outfile.WriteLine(folderIdx.Name & ";" & folderIdx.DateCreated & ";" & folderIdx.DateLastModified) Next outfile.Close |
|
|
|
|
|
#10 |
|
Newbie Member
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: List All Files in Folder using VBScript
Hi: I am a novice to VBS. I was wodering if it is possible to read thru the files in a folder and capture the last line in every file(csv file) and write to a logfile that has the name(with date and time) Also, is it possible that when capturing the last line , I have to extract the last field value compare it with a base value and if it is greater than the base value then write it the log file. Since it loops thru each file in the folder, base values for each file keep changing. I am not quite sure how to do it. Any help would be great. Thanks, Yukta. |
|
|
|
![]() |
|
| Currently Active Users Reading This Article: 2 (0 members and 2 guests) | |
| Article Tools | Search this Article |
| Display Modes | |
| Bookmarks | |
|
|
|
|||||||||||||||||||||||||||||||||||||