|
All file interactions in ASP are done through the File System Object that is included with IIS. It is used to to manipulate files, folders, and directory paths.
The FileSystemObject
The FileSystemObject object is used to access the file system on a server. The FileSystemObject can be used to manipulate files, folders, and directory paths. Here is an example code for creating a text file.
<%
dim fsObj,filename
set fsObj=Server.CreateObject("Scripting.FileSystemObject")
set filename= fsObj.CreateTextFile("d:\testing.txt",true)
filename.WriteLine("Hello World!")
filename.Close
set filename =nothing
set fsObj=nothing
%>
The File Object
The File object is used to return information about a specified file. To retrieve a File Object in ASP you must know the relative or complete file path to the desired file.
<%
Dim fsObj,fileInfo
Set fsObj=Server.CreateObject("Scripting.FileSystemObject")
Set fileInfo=fsObj.GetFile("c:\testing.txt")
Response.Write("File created: " &fileInfo.DateCreated)
set fileInfo=nothing
set fsObj =nothing
%>
The Folder Object
The Folder object is used to return information about a specified folder. You must provide the complete or relative path of the folder to get the Folder object.
<%
Dim fsObj, folderObj
Set fsObj = Server.CreateObject("Scripting.FileSystemObject")
Set folderObj= fsObj.GetFolder("c:\testfolder")
Response.Write("Current folder is: " & folderObj.Name)
For Each fileItem In folderObj.Files
Response.Write("<br />" & fileItem.Name)
Next
Set myFolderO = nothing
Set fsObj= nothing
%> |