ASP File objekt
- Forrige side ASP Drive
- Næste side ASP Folder
File-objektet bruges til at returnere information om den angivne fil.
Eksempel
- Hvornår blev filen oprettet?
- Dette eksempel viser, hvordan man først opretter et FileSystemObject-objekt og derefter bruger File-objektets DateCreated-egenskab til at få den dato og klokkeslæt, hvor den angivne fil blev oprettet.
- Hvornår blev denne fil ændret?
- Dette eksempel viser, hvordan man bruger DateLastModified-egenskaben til at få den dato og klokkeslæt, hvor den angivne fil blev ændret.
- 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 on 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 create an instance of this File object through the GetFile method of the FileSystemObject object, or through the Files property of the Folder object.
The following code demonstrates how to use the GetFile method of the FileSystemObject object to create an instance of the 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 | Beskrivelse |
---|---|
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. |
Metode
Metode | Beskrivelse |
---|---|
Copy | Kopier den angivne fil fra en placering til en anden. |
Delete | Slet den angivne fil. |
Move | Flyt den angivne fil fra en placering til en anden. |
OpenAsTextStream | Åbn den angivne fil og returner en TextStream objekt for at få adgang til denne fil. |
- Forrige side ASP Drive
- Næste side ASP Folder