How to access properties of files and folders on the server?
Accessing the properties of the files and the folders on the server can be easily
accomplished with the help of the FileSystemObject methods. You need to create
an instance of the FileSystemObject and then use the methods of that object. There
are several properties and methods for the FileSystemObject that allows you to
work with the files on the server.
We shall see some code that works on the files on a server. For this we need to have some files on the server. Assuming that you have a file called Log.txt in the same directory as that of the .asp file that has the code to access the properties of the files; the code could be something like given below: 1.
<% The
second line of the code given above has the declarations for the objects that
will be used to access the properties of the files. An instance of the FileSystemObject
is created in the 3rd and the 4th line. The GetFile method of the FileSystemObject
is used to access the file Log.txt. We are using the Server.MapPath
method to access the file. You know that the MapPath is used to convert the relative
path to the physical path which the gives the path exactly starting with the drive
name. You should check the code by replacing the Line 7 of the code with other properties and methods so that you know how those properties are also accessed. For example the Line 7 could be modified as: ·
Response.Write objFile.DateCreated These are
some of the properties that can be accessed. There are also other properties
like, Name, ShortPath, ParentFolder, and Type. For more details and code
samples on these you can always refer the documentation provided for these
in the Microsoft website.
|