Wednesday, April 13, 2011

Working with FileSystemObject- Part 1

How to get List of subfolder and count of Subfolder

Set fso = CreateObject("Scripting.FileSystemObject")

Set b = fso.GetFolder("C:\TestEnvironments")
Set c = b.SubFolders
foldercount=c.Count
msgbox foldercount
For Each d in c
e=e&d.name&vbnewline
Next
msgbox e

Working with some file system methods

Set f1 = CreateObject("Scripting.FileSystemObject")

Set f2 = f1.GetFile("c:\path.txt")
Filecreatedon = "File was Created on: "&f2.DateCreated
Msgbox Filecreatedon
fileDateLastModified="file path is:" &f2.DateLastModified
Msgbox fileDateLastModified
filetype="File type is:" &f2.Type
Msgbox filetype
filepath="file path is:" &f2.Path
msgbox filepath
filesize="file path is:" &f2.Size
msgbox filesize
'To find the type of file extension from given folder
Set ParentFld = fso.GetFolder ("E:\Trupti")

For Each oFile In ParentFld.files
' msgbox fso.GetExtensionName(oFile.Path )
'to find the extensionname of file
If fso.GetExtensionName(oFile.Path ) = "docx" Or fso.GetExtensionName(oFile.Path ) = "doc" then
txtCount = txtCount + 1
END IF
Next
msgbox "file type is:" &txtCount

No comments:

Post a Comment