VBScript Basics, Part 27 | Get File – Folder (Properties)


VBScripting (.vbs) Basic tutorial on how to get a file or folder to find out certain properties about it, such as its name, size, type, location, date, etc…

Code Example:
______________________________________________________

Option Explicit
Dim objFso, file, data
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set file = objFso.GetFile(“C:UsersJeremyDesktopmyfile.txt”)

data = “Attributes: ” & file.Attributes &vbLf
data = data & “DateCreated: ” & file.DateCreated &vbLf
data = data & “DateLastModified: ” & file.DateLastModified &vbLf
data = data & “Drive: ” & file.Drive &vbLf
data = data & “Name: ” & file.Name &vbLf
data = data & “ParentFolder: ” & file.ParentFolder &vbLf
data = data & “Path: ” & file.Path &vbLf
data = data & “Size: ” & file.Size &vbLf
data = data & “Type: ” & file.Type &vbLf

MsgBox data
______________________________________________________

Option Explicit
Dim objFso, folder, data
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set folder = objFso.GetFolder(“C:UsersJeremyDesktopmyfolder”)

data = “Attributes: ” & folder.Attributes &vbLf
data = data & “DateCreated: ” & folder.DateCreated &vbLf
data = data & “DateLastModified: ” & folder.DateLastModified &vbLf
data = data & “Drive: ” & folder.Drive &vbLf
‘data = data & “Files: ” & folder.Files &vbLf
data = data & “Name: ” & folder.Name &vbLf
data = data & “ParentFolder: ” & folder.ParentFolder &vbLf
data = data & “Path: ” & folder.Path &vbLf
data = data & “Size: ” & folder.Size &vbLf
‘data = data & “SubFolders: ” & folder.SubFolders &vbLf
data = data & “Type: ” & folder.Type &vbLf

MsgBox data
______________________________________________________

Know the Basics:
——————————————————————————————
Set objFso = CreateObject(“Scripting.FileSystemObject”)
objFso.GetFile(“LOCATION & FILENAME”)
objFso.GetFolder(“LOCATION”)
——————————————————————————————