Thursday, February 26, 2009

Get number of Files in a Folder

Hi All,
Use the following way for finding the number of files in a folder.

Code:

Set objFileSysOb = CreateObject("Scripting.FileSystemObject")
Set colFolderName = objFileSysOb.GetFolder("give entire folder path here")
Set vFiles =colFolderName.Files
Sno=0
For each i in vFiles
d=Split(i,"\")
FileName=d(ubound(d))
Sno=Sno+1
msgbox "File "&Sno&" : "&FileName
Next

msgbox "Number of files in Current Folder : "&vFiles.count

Output :

1 comment:

  1. Hi Sreekanth,

    Thank you verymuch for your post. I want to read each file in the folder. Can you please help me out???

    Regards,
    Imran Khan.
    imruin@gmail.com

    ReplyDelete