Obiekt pliku ASP
Obiekt File służy do zwracania informacji o określonym pliku.
Więcej przykładów
Jak uzyskać datę i godzinę ostatniej modyfikacji określonego pliku.
Jak uzyskać datę i godzinę ostatniego dostępu do określonego pliku.
Jak zwrócić atrybuty określonego pliku.
Obiekt pliku
Obiekt File służy do zwracania informacji o określonym pliku.
Aby pracować z właściwościami i metodami obiektu File, musisz utworzyć instancję obiektu File za pomocą obiektu FileSystemObject. Pierwszy; utwórz obiekt FileSystemObject, a następnie utwórz wystąpienie obiektu File za pomocą metody GetFile obiektu FileSystemObject lub właściwości Files obiektu Folder.
W poniższym kodzie zastosowano metodę GetFile obiektu FileSystemObject w celu utworzenia wystąpienia obiektu File i właściwości DateCreated w celu zwrócenia daty utworzenia określonego pliku:
Przykład
<%
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
%>
Właściwości i metody obiektu File są opisane poniżej:
Nieruchomości
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 |
Metody
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 |