deleting files from a folder

Results 1 to 2 of 2

Thread: deleting files from a folder

  1. #1
    jeps0 Guest

    Default deleting files from a folder

    I use the following script to list all files in a specific folder. Can I use FileSystemObject to delete files in that folder? I&#039;d like to list all files with a "remove" button next to each filename. I&#039;m not very handy when it comes to FileSystemObject, so please be very specific if you answer to this =)<BR><BR>&#060;%<BR>dim oFolder, oFSO, oFiles, pFile<BR><BR>&#039;all filesystemobjects<BR>set oFSO = server.createobject("scripting.FileSystemObject")< BR><BR>&#039;the folder to browse<BR>folder = Server.MapPath("test")<BR>set oFolder = oFSO.GetFolder(folder)<BR><BR>&#039;returns a collection of files<BR>set oFiles = oFolder.Files<BR><BR>for each pFile in oFiles<BR> response.write & "/" & & "&lt;br&gt;"<BR>next<BR><BR>set oFiles = nothing<BR>set oFolder = nothing<BR>set oFSO = nothing<BR>%&#062;<BR>

  2. #2
    Rae Guest

    Default RE: deleting files from a folder

    Think this will work:<BR><BR>for each pFile in oFiles<BR> response.write & "/" & & "&#060;input type = submit value = Remove name = " & & "&#062;<BR>"<BR>next<BR><BR>Then, in the code you write to handle the form, use the following to retrieve the file&#039;s name:<BR><BR>strFileName = Request.QueryString.Key(1)<BR><BR>(obviously the above will only work if you are using GET and the button is the first element in the QueryString)<BR><BR>Then, to remove that file, you&#039;ll have to create a File object using strFileName (e.g. set fileobject = filesysobj.GetFile(folder&strFileName)).<BR><BR>On ce you&#039;ve created the object, you can delete it:<BR><BR>fileobject.Delete True<BR><BR>Hope this works!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts