0
eLn1r0's Avatar, Join Date: Sep 2009
Newbie Member
Hallo

This is what i was surching for a very long time. But i must filter the files i want listed in the .txt file by the extension of the files.. could someone help me?
0
pascalsk's Avatar
Newbie Member
Dis is great Keep it up. i hope to learn more from u.
0
chmod777's Avatar, Join Date: Sep 2009
Newbie Member
Quote:
Originally Posted by SaswatPadhi View Post
It's really simple ! You just need to check <folder>.folders instead of <folder>.files.
Code: vb
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)
' CHANGE STARTS HERE :
Set objColFolders = objFolder.Folders

For Each tfolder In objColFolders
&nbsp;&nbsp;&nbsp;&nbsp;objNewFile.WriteLine(tfolder.Name)
Next
' CHANGE DONE.
objNewFile.Close

'**Browse4Folder Function
Function Browse4Folder(strPrompt, intOptions, strRoot)
&nbsp;&nbsp;&nbsp;&nbsp;Dim objFolder, objFolderItem

&nbsp;&nbsp;&nbsp;&nbsp;On Error Resume Next

&nbsp;&nbsp;&nbsp;&nbsp;Set objFolder = objShell.BrowseForFolder(0, strPrompt, intOptions, strRoot)
&nbsp;&nbsp;&nbsp;&nbsp;If (objFolder Is Nothing) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ws cript.Quit
&nbsp;&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;&nbsp;&nbsp;Set objFolderItem = objFolder.Self
&nbsp;&nbsp;&nbsp;&nbsp;Browse4Folder = objFolderItem.Path
&nbsp;&nbsp;&nbsp;&nbsp;Set objFolderItem = Nothing
&nbsp;&nbsp;&nbsp;&nbsp;Set objFolder = Nothing
End Function
I have tried this in both Windows Vista, and again on XP (thinking that maybe Vista had issues), and I cannot get this to read the folders. It just creates an empty 'filelist.txt' file. I have not modified this script in any way, and have tried diff. folders. Any suggestions from anyone?
SaswatPadhi like this
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Quote:
Originally Posted by chmod777 View Post
I have tried this in both Windows Vista, and again on XP (thinking that maybe Vista had issues), and I cannot get this to read the folders. It just creates an empty 'filelist.txt' file. I have not modified this script in any way, and have tried diff. folders. Any suggestions from anyone?
Hi,

Thanx for reporting.

There was a typo at this line :Set objColFolders = objFolder.Folders
It should read :Set objColFolders = objFolder.SubFolders.

Correct code [ TESTED ] is :
Code: VB
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("MyComputer")
strFolderPath = Browse4Folder(strPrompt, intOptions, strTargetPath)

Set objNewFile = objFSO.CreateTextFile(strFolderPath & "\filelist.txt", True)
Set objFolder = objFSO.GetFolder(strFolderPath)
' CHANGE STARTS HERE :
Set objColFolders = objFolder.SubFolders

For Each tfolder In objColFolders
    objNewFile.WriteLine(tfolder.Name)
Next
' CHANGE DONE.
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
chmod777 like this
0
chmod777's Avatar, Join Date: Sep 2009
Newbie Member
Well that did the trick. Thanks.
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
My pleasure
0
DivinationX's Avatar, Join Date: Nov 2009
Newbie Member
How do i code such that, the filename that is captures will be stored into an array of strings? Thanks!
0
chuck42's Avatar
Newbie Member
Is it possible to tiune this skript, so I get a file contianing fileextention, size and owner of the file?
(I found something similar in asp: classicasp.aspfaq.com/files/directories-fso/how-do-i-find-the-owner-author-and-other-properties-of-a-file.html but I dont know how to do so in vbs or similar
0
hanleyhansen's Avatar, Join Date: Jan 2008
Pro contributor
This is very good and fairly simple. It would be nice if you explained each line for those not familiar with VB
0
RomuloAraujo's Avatar, Join Date: Feb 2010
Newbie Member
Hi here,

Very good example guys. However, I would like to push a little bit ... Let's say I have a folder containing 140k .CSVs files (avg size 5k) and I want to list them all files not to a file but to memory into an array or something... so then after listing I would be about concatenate all those files into one single big.CSV file.

is that possible?

Rom