VBScript - Windows Scripting Host (The File Object)

December 2016




The File object

The File object is obtained using FileSystemObject. It is used to manipulate or obtain information about a file. To use a File object simply:
  • Create an instance of the FSO object:
    • Set objetFSO = CreateObject("Scripting.FileSystemObjet)
  • Open a file by creating a File object, for example:
    • Set Fichier = objetFSO.GetFile("c:\myfile")
  • Use a method or property of the File object, for example:
    • Wscript.Echo objetFSO.ParentFolder


Here is a summary of collections, properties and methods of the File object:

Objet File
Collections Propreties Methods
Attributes
DateCreated
DateLastAccessed
DateLastModified
Drive
Name
ParentFolder
Path
ShortName
ShortPath
Size
Type
Copy
Delete
Move
OpenAsTextStream

The Attributes property

The Attributes property allows you to set or retrieve the attributes of a particular file or folder. The returned value, defining the attributes of the file is calculated by summing the values ??of the attributes of the file:
Value Description
0Normal. File without attribute
1ReadOnly. Read-only file that can be read only (not editable).
2Hidden. Hidden file
4System. System file, necessary for the proper functioning of the system
8Volume. Volume label of a disk drive.
16Directory. Folder (Directory)
32Archive. File modified since the previous backup.
64Alias. This is a shortcut.
128Compressed. It is a compressed file

For an archive, hidden, read-only, the return value will be:
32+2+1 = 35

DateCreated property

DateCreated property allows you to set or retrieve the date and time of creation of a particular file or folder.

DateLastAccessed property

DateLastAccessed property allows you to set or retrieve the date and time of last access of a particular file or folder.

DateLastModified property

DateLastModified property to set or retrieve the date and time at which the last modification was made to a file or folder

Drive property

Drive property contains the name of the drive on which the target file or folder is located.

Name property

The Name property allows you to set or retrieve the name of the file or folder in question, without indicating the path.

ParentFolder property

The ParentFolder property contains the name of the parent folder of the specified file or folder.

Path property

The Path property contains the absolute path of the specified file or folder.

ShortName

The ShortName property contains the name of the specified file or folder in its abbreviated form.

ShortPath property

The ShortPath property contains the path to the file or folder specified in its abbreviated form.

Size property

The Size property contains the size of the specified file, in bytes.

Type property

The Type property containsinformation about the type of the specified file or folder.

Copy method

Copy method contains information about the type of file or folder specified.

Original document published on CommentcaMarche.net

Related :

This document entitled « VBScript - Windows Scripting Host (The File Object) » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.