ASP - bestandsobject
Het File-object wordt gebruikt om informatie over een opgegeven bestand te retourneren.
Meer voorbeelden
Hoe u de datum en tijd kunt krijgen waarop een bepaald bestand voor het laatst is gewijzigd.
Hoe u de datum en tijd kunt krijgen waarop een bepaald bestand voor het laatst is geopend.
Hoe de attributen van een gespecificeerd bestand te retourneren.
Het bestandsobject
Het File-object wordt gebruikt om informatie over een opgegeven bestand te retourneren.
Om met de eigenschappen en methoden van het File-object te werken, moet u een instantie van het File-object maken via het FileSystemObject-object. Eerste; maak een FileSystemObject-object en start vervolgens het File-object via de GetFile-methode van het FileSystemObject-object of via de eigenschap Files van het Folder-object.
De volgende code gebruikt de methode GetFile van het FileSystemObject-object om het File-object te instantiëren en de eigenschap DateCreated om de datum te retourneren waarop het opgegeven bestand is gemaakt:
Voorbeeld
<%
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
%>
De eigenschappen en methoden van het File-object worden hieronder beschreven:
Eigenschappen
Property | Description |
---|---|
Attributes | Sets or returns the attributes of a specified file |
DateCreated | Returns the date and time when a specified file was created |
DateLastAccessed | Returns the date and time when a specified file was last accessed |
DateLastModified | Returns the date and time when a specified file was last modified |
Drive | Returns the drive letter of the drive where a specified file or folder resides |
Name | Sets or returns the name of a specified file |
ParentFolder | Returns the folder object for the parent of the specified file |
Path | Returns the path for a specified file |
ShortName | Returns the short name of a specified file (the 8.3 naming convention) |
ShortPath | Returns the short path of a specified file (the 8.3 naming convention) |
Size | Returns the size, in bytes, of a specified file |
Type | Returns the type of a specified file |
Methoden:
Method | Description |
---|---|
Copy | Copies a specified file from one location to another |
Delete | Deletes a specified file |
Move | Moves a specified file from one location to another |
OpenAsTextStream | Opens a specified file and returns a TextStream object to access the file |