|
||
Wise ASP - FileSystemObject ObjectThe FileSystemObject object provides access to the computer's file system, allowing us to manipulate text files, folders and drives from within our code. It's part of the Scripting Object. We can create an instance of the FileSystemObject in JScript using:
var fso = Server.CreateObject("Scripting.FileSystemObject")
The Folder ObjectThe Folder object provides access to the file system on a specified drive. You can also the Folder to traverse directories on a particular drive. After you create an instance of the FileSystemObject object, you need to declare a variable that will server as your Folder object. Then you need to use the GetFolder method to get your specified folder. Each directory object has a property called Files, which is a collection of File objects. This represents the list of files the directory specified by your variable folder.Here is some JScript code to list all the files in a particular directory, called "c:\inetpub\wwwroot" :
var myPath = "c:\inetpub\wwwroot";
var fso = Server.CreateObject("Scripting.FileSystemObject");
var folder = fso.GetFolder(myPath);
var fileCollection = folder.Files;
var items = new Enumerator(fileCollection);
while(!items.atEnd()) {
i = items.item()
Response.write(i.name + " -- ");
Response.write(i.DateLastModified + "<br>");
items.moveNext();
}
| ||
| ||