![]() |
WebCheatSheet.com |
![]() |
ASP Folder Object |
The folder object represents a specified file folder on the current machine. We can use the properties and methods of the Folder object to traverse directories on the drive, and to get at all the properties of this or any other folder. To work with the Folder object's properties and methods, you need to create an instance of the FileSystemObject object first and then instantiate the Folder object through the GetFolder method. Also you can get a Folder object reference from the Drive object, by using the RootFolder property. The collections, properties and methods of the Folder object are as follows: Collections
Properties
Methods
How to use the ASP Folder Object In the following example we create an instance of the FileSystemObject object and then use the GetFolder method to instantiate the Folder object. After that we use The Folder object properties to get the information about the specified folder: <%
Dim objFSO, objDrive 'Create a FileSystemObject instance Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 'Using the GetDrive method of FileSystemObject object, initialize a Drive object Set objFolder = objFSO.GetFolder("c:\test") 'Retrieve information about the folder Response.Write "Name: " & objFolder.Name & "<br />" Response.Write "ShortName: " & objFolder.ShortName & "<br />" Response.Write "Size: " & objFolder.Size & " bytes <br />" Response.Write "Type: " & objFolder.Type & "<br />" Response.Write "Path: " & objFolder.Path & "<br />" Response.Write "ShortPath: " & objFolder.ShortPath & "<br />" Response.Write "Created: " & objFolder.DateCreated & "<br />" Response.Write "LastModified: " & objFolder.DateLastModified & "<br /><br />" %> The example below iterates through all the folders in the root of drive C:, and displays the date and time that each one was created: <% Dim objFSO, objDrive 'Create a FileSystemObject instance Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 'Using the GetDrive method of FileSystemObject object, initialize a Drive object Set objDrive = objFSO.GetDrive("c:") 'Get a reference to the root folder Set objRoot = objDrive.RootFolder 'Get a reference to the folders collection Set colFolders = objRoot.SubFolders 'Retrieve information about all the folders in within this folder For Each objFolder in colFolders Response.Write "Name: " & objFolder.Name & "<br />" Response.Write "LastModified: " & objFolder.DateLastModified & "<br /><br />" Next %> |
![]() |
![]() |
Copyright © 2005-2007 www.WebCheatSheet.com All Rights Reserved. |