Cari Blog Ini

19 Juli 2013

How To Get File Name - File Size and Date Modified in Folder

Want to :

* Get file name, file size and date modified in Folder 

* Using VBScript

* Using scripting File System Object






Step : 

1. Example of Folder



2. Create new file, example name "GetFileName_Local.vbs"
and file the below code :

-----CODE START-----
Dim fso
Dim ObjFolder
Dim ObjOutFile
Dim ObjFiles
Dim ObjFile

'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")

'Getting the Folder Object
Set ObjFolder = fso.GetFolder("C:\WORK\Local")

'Creating an Output File to write the File Names
Set ObjOutFile = fso.CreateTextFile("C:\WORK\GetFileName_Local_LOG.csv")

'Getting the list of Files
Set ObjFiles = ObjFolder.Files

ObjOutFile.WriteLine(  Chr(34) & "File_Name" & Chr(34) & "," & Chr(34) & "Date_Modified" & Chr(34) & "," & Chr(34) & "File_Size" & Chr(34) )

'Writing Name and Path of each File to Output File
For Each ObjFile In ObjFiles

    ObjOutFile.WriteLine(  Chr(34) &  ObjFile.Name & String(50 - Len(ObjFile.Name), " ") & Chr(34) & "," & Chr(34) & ObjFile.DateLastModified & Chr(34) & "," & Chr(34) & ObjFile.Size & Chr(34)  )
Next

ObjOutFile.Close
-----CODE END-----



3. Try to run the script, name "GetFileName_Local.vbs"


4. The file output, name "GetFileName_Local_LOG" will created automatically.


5. Try to open the output file, using Microsoft Excel



Source:
http://easyprograming.com/index.php/vb-script/34-list-all-files-and-subfolders-inside-a-folder-using-vbscript