Forums

ASP

This topic is locked

Deleting Files From A Directory Dynamically

Posted 09 May 2002 23:57:57
1
has voted
09 May 2002 23:57:57 Lewis Richards posted:
Is it possible. I was wondering if there may be an extention or some ASP code that will allow me to create a form that will all me to see a particular directory, choose a file then delete it. Something opposite of Pure ASP Upload.
Your help is greatly appreciated.
Thanks

Replies

Replied 10 May 2002 00:46:04
10 May 2002 00:46:04 Andrew Watson replied:
You need to use the file system object...

<pre id=code><font face=courier size=2 id=code>
&lt;%
dim fs
Set fs=Server.CreateObject("Scripting.FileSystemObject"
if fs.FileExists("c:\test.txt" then
fs.DeleteFile "c:\test.txt"
end if
set fs=nothing
%&gt;

</font id=code></pre id=code>

That will delete the file...an error is returned if the file doesn't exist.

have a look here and youll get the other properties like getfolder etc....

www.w3schools.com/asp/asp_ref_filesystem.asp

Hope this is of some help.

:: Son, im Thirty.... ::
Replied 23 May 2002 00:57:21
23 May 2002 00:57:21 Josh Cooper replied:
Here's how you can list files from a particular directory on the server:

<font face='Courier New'>&lt;%
' The following is for directory content listing
Set dirObj = Server.CreateObject("Scripting.FileSystemObject"

' THIS NEEDS TO CHANGE ACCORDING TO THE SERVER'S PATH MAPPING
Set dirList = dirObj.GetFolder("C:\absolute\path\to\list"
%&gt;</font id='Courier New'>

That creates the dirList object for listing. Now, to step through each file in the directory (using a menu selection form object):

<font face='Courier New'>
&lt;select name="select"&gt;
&lt;%
For each filefound in dirList.files
%&gt;
&lt;option value="&lt;% =filefound.Name %&gt;"&gt;
&lt;% =filefound.Name %&gt;
&lt;/option&gt;
&lt;%
Next
%&gt;
&lt;/select&gt;</font id='Courier New'>

Use leed's code in the previous reply to delete files. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Edited by - Silix on 23 May 2002 01:01:16

Reply to this topic