Tuesday, April 20, 2010

Display of File Properties in VB Scrip using FileSystemObject

Back To File System Object Page

How to display File Properties in VB script?

Using the File System Object method CreateFile we create a File and Using the GetFile Method we get the newly created File. Then we use the name, size etc methods to get the properties of the file.


'Create a Folder using FSO or FileSystemObject
'Script to print the different properties of a Text File

'Step 1: Create an object variable that interacts with the File System Object Library
Set Fso = CreateObject("Scripting.FileSystemObject")

'Step 2: use the CreateTextFile to Create a Text File
Fso.CreateTextFile("F:\Text.txt")

'Step 3: Use the GetFile Method to get the information of the file and set it to a Object Variable
Set F=Fso.GetFile("F:\Text.txt")

'Step 4: Print the Properties of the File using various

MsgBox "The File name is: "&f.name&"" &vbnewline& "The File Size is: "&f.size&""&vbnewline& "The File Creation Date is: "&f.DateCreated&""&vbnewline& "The File Last Modified on: "&f.DateLastModified

Back To File System Object Page

No comments:

Post a Comment