ASP File-objekt

Filobjektet används för att returnera information om en specifik fil.

Exempel

När skapades filen?
Detta exempel visar hur man först skapar ett FileSystemObject-objekt och sedan använder filobjektets DateCreated-attribut för att få datum och tid för när en specifik fil skapades.
När ändrades denna fil?
Detta exempel visar hur man använder DateLastModified-attributet för att få datum och tid för när en specifik fil har ändrats.
When was this file accessed?
This example demonstrates how to use the DateLastAccessed property to obtain the date and time when the specified file was last accessed.
Return the attributes of the specified file
This example demonstrates how to use Attributes to return the attributes of the specified file.

File object

The File object is used to return information about the specified file.

To operate the properties and methods of the File object, we need to create an instance of the File object through the FileSystemObject. First, create a FileSystemObject object, and then use the GetFile method of the FileSystemObject object, or use the Files property of the Folder object to illustrate this File object.

The following code demonstrates how to use the GetFile method of the FileSystemObject object to illustrate this File object and use the DateCreated property to return the date when the specified file was created:

<%
Dim fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile("c:\test.txt")
Response.Write("File created: " & f.DateCreated)
set f=nothing
set fs=nothing
%>

Output:

File created: 8/8/2008 10:01:19 AM

Properties and methods of the File object

Attributes

Attributes Beskrivning
Attributes Set or return the attributes of the specified file.
DateCreated Return the date and time when the specified file was created.
DateLastAccessed Return the date and time when the specified file was last accessed.
DateLastModified Return the date and time when the specified file was last modified.
Drive Return the drive letter of the drive where the specified file or folder is located.
Name Set or return the name of the specified file.
ParentFolder Return the parent folder object of the specified file or folder.
Path Return the path of the specified file.
ShortName Return the short name of the specified file (8.3 naming convention).
ShortPath Return the short path of the specified file (8.3 naming convention).
Size Return the size of the specified file (in bytes).
Type Return the type of the specified file.

Metod

Metod Beskrivning
Copy Kopiera en specificerad fil från en plats till en annan.
Delete Ta bort en specificerad fil.
Move Flytta en specificerad fil från en plats till en annan.
OpenAsTextStream Öppna en specificerad fil och returnera en TextStream-objekt för att komma åt denna fil.