Objet de fichier ASP


L'objet File est utilisé pour renvoyer des informations sur un fichier spécifié.


Plus d'exemples


Comment obtenir la date et l'heure auxquelles un fichier spécifié a été modifié pour la dernière fois.


Comment obtenir la date et l'heure du dernier accès à un fichier spécifié.


Comment renvoyer les attributs d'un fichier spécifié.


L'objet fichier

L'objet File est utilisé pour renvoyer des informations sur un fichier spécifié.

Pour travailler avec les propriétés et les méthodes de l'objet File, vous devrez créer une instance de l'objet File via l'objet FileSystemObject. D'abord; créez un objet FileSystemObject, puis instanciez l'objet File via la méthode GetFile de l'objet FileSystemObject ou via la propriété Files de l'objet Folder.

Le code suivant utilise la méthode GetFile de l'objet FileSystemObject pour instancier l'objet File et la propriété DateCreated pour renvoyer la date à laquelle le fichier spécifié a été créé :

Exemple

<%
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
%>


Les propriétés et les méthodes de l'objet File sont décrites ci-dessous :

Propriétés

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

Méthodes

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