||The FileSystemObject, which provides access to the Web server's file system, contains a method called |
DeleteFile. As its name implies,
DeleteFile is used to delete a file from the Web server's file system.
DeleteFile takes one required and one optional parameter. The first parameter, which is required, is the physical file name of the file to delete, like
C:\MyFiles\foo.txt. The second parameter, which is option, is a Boolean value (True or False) and, if not specified, defaults to a value of
False. This second parameter determines whether or not read-only files can be deleted. If you will be deleting read-only files, you must specify the second parameter as True.
So, if we wanted to delete the file
C:\Foo\readme.txt, we could use the following code:
'Create the FileSystemObject
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Delete the file
objFSO.DeleteFile "C:\Foo\readme.txt", False
Since we specify the second parameter as
C:\Foo\readme.txt will not be deleted if it is marked as a read-only file.
DeleteFile to work properly, the anonymous Internet user account must have Delete permissions for the file/directory to be deleted.
On a side note, if you want to convert a local URL path (like
/WebDir1/FileName.html) into a physical file path (like
C:\Inetpub\wwwroot\WebDir1\FileName.html) simply use the
Server.MapPath function. For more information on
Server.MapPath be sure to read: Using
-- View the technical docs for