Methods
The Copy Method
The Copy method copies a file or folder.
Syntax
object.Copy(destination, overwrite)
Part Description
object Required. The name of a File or Folder Object
destination Required. Where to copy the file or folder
overwrite Optional. Sets whether an existing file or folder
can be overwritten. True
indicates that the file/folder can be overwritten, False
indicates that the file/folder
can not be overwritten. True is default
Example
dim fs,txtfile
set fs=CreateObject("Scripting.FileSystemObject")
set txtfile=fs.GetFile("c:\testfile.txt") txtfile.Copy("c:\mydocuments\test\test2.txt")
set txtfile=nothing
set fs=nothing
The Delete Method
The Delete method deletes a specified file or folder.
Syntax
object.Delete force
Part Description
object Required. The name of a File or Folder Object
force Optional. Sets whether a read-only file or folder are
deleted. True indicates that
a read-only file/folder are deleted, False indicates that it is
not deleted. False is
default
Example
dim fs,txtfile
set fs=CreateObject("Scripting.FileSystemObject")
set txtfile=fs.GetFile("c:\testfile.txt")
txtfile.Delete
set txtfile=nothing
set fs=nothing
The Move Method
The Move method moves a file or folder.
Syntax
object.Move destination
Part Description
object Required. The name of a File or Folder Object
destination Required. Where to move the file or folder
Example
dim fs, txtfile
set fs=CreateObject("Scripting.FileSystemObject")
Set txtfile = fs.GetFile("c:\testfile.txt")
txtfile.Move("c:\mydocuments\test\")
set txtfile=nothing
set fs=nothing
The OpenAsTextStream Method
The OpenAsTextStream method opens a file and returns a
TextStream object to access the file.
Syntax
object.OpenAsTextStream(iomode, format)
Part Description
object Required. The name of a File Object
iomode Optional. How to open the file. 1 = ForReading Opens
a file for reading. It is
not possible to write to this file 2 = ForWriting Opens a file
for writing. It is not
possible to read from this file 8 = ForAppending Opens a file
and write to the
end of the file
format Optional. The format of the file. 0 = TristateFalse
Opens the file as ASCII. This
is the default -1 = TristateTrue Opens the file as Unicode -2 =
TristateUseDefault Opens the file using the system default
Example
1.
When
was the File Created?
This example demonstrates how to first create a FileSystem
Object, and then use the DateCreated property of the File Object
to get the date and time a specified file was created.
Coding
<html>
<body>
<%
dim fs, f
set fs=CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was created on: " &
f.DateCreated)
set f=nothing
set fs=nothing
%>
</body>
</html>
Output
The file testread.txt was created on: 28.04.00 15:01:17
2.
When
was the File Last Modified?
This example demonstrates how to use the DateLastModified
property to get the date and time a specified file was last
modified.
Coding
<html>
<body>
<%
dim fs, f
set fs=CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was last modified on: " &
f.DateLastModified)
set f=nothing
set fs=nothing
%>
</body>
</html>
Output
The file testread.txt was last modified on: 15.06.00 15:12:04
3.
When
was the File Last Accessed?
This example demonstrates how to use the DateLastAccessed
property to get the date and time a specified file was last
accessed.
Coding
<html>
<body>
<%
dim fs, f
set fs=CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was last accessed on: " &
f.DateLastAccessed)
set f=nothing
set fs=nothing
%>
</body>
</html>
Output
The file testread.txt was last accessed on: 12.08.00 14:35:28
4.
Attributes
This example demonstrates how to use the Attributes property to
return the attributes of a specified file.
Coding
<html>
<body>
<%
dim fs, f
set fs=CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The attributes of the file testread.txt are: " &
f.Attributes)
set f=nothing
set fs=nothing
%>
</body>
</html>
Output
The attributes of the file testread.txt are: 32
Properties