Delete multiple files?

Results 1 to 2 of 2

Thread: Delete multiple files?

  1. #1
    Brandon Block Guest

    Default Delete multiple files?

    Hi ! <BR><BR>I have a problem when deleting servral files, i have a form page where the user selects by marking check boxes which files that should be deleted, on the destination page i loop through the database and delete the database record and then delete the physical file from the server.<BR><BR>It seems that the physical file deletion only will delete one file , and then return a error message that the file has the wrong filename or filenummber (Microsoft VBScript (0x800A0034) )<BR><BR><BR>heres the code<BR><BR>&#039;******************************** **********&#039;<BR>&#039;*** Declare variables ***&#039;<BR>&#039;******************************* ***********&#039;<BR><BR>Dim dbCon &#039;Connection string<BR>Dim rsUpload &#039;RecordSet<BR>Dim lgtUploadUrl &#039;Http Variable<BR><BR><BR>lgtUploadUrl = Request("lgtUploadUrl")<BR>IDArray = Split(lgtUploadUrl, ",", -1, 1)<BR><BR><BR><BR>&#039;************************** *******************&#039;<BR>&#039;*** Open record set. ***&#039;<BR>&#039;******************************* **************&#039;<BR><BR>set dbCon = Server.CreateObject("ADODB.Connection")<BR>set rsUpload = Server.CreateObject("ADODB.Recordset")<BR>dbCon.Op en "whatever"<BR><BR><BR><BR>&#039;****************** ***************************&#039;<BR>&#039;*** Loop array. ***&#039;<BR>&#039;******************************* **************&#039;<BR><BR>FOR I = LBound(IDArray) to UBound(IDArray)<BR>lgtUploadUrl = IDArray(I)<BR><BR> set rsUpload = Server.CreateObject("ADODB.Recordset")<BR> &#039; Get the Record to delete the File in database<BR> rsUpload.Open "DELETE FROM lgtUpload WHERE lgtUploadUrl =&#039;" & lgtUploadUrl & "&#039;" , dbCon,1<BR> Set rsUpload = Nothing<BR><BR> &#039; Delete the Physical file on server<BR> Set DelObj = CreateObject("Scripting.FileSystemObject")<BR> DelObj.DeleteFile "" & lgtUploadUrl<BR> Set DelObj = Nothing<BR>Next<BR><BR> dbCon.Close<BR> Set dbCon = Nothing<BR><BR><BR><BR>&#039;end code<BR><BR><BR>Hope you can help me out here<BR>

  2. #2
    RDM Guest

    Default A few things to check...

    Why not just use the existing connection object&#039;s dbCon.Execute method? Would be quicker than creating a separate object. Also, why not issue one delete like:<BR><BR>dbCon.Execute "delete from lgtUpload where lgtUploadURL in (&#039;file1&#039;,&#039;file2&#039;,&#039;file3&# 039;)" &#039; Values obtained from your array.<BR><BR>Removes the need for several trips to the database.<BR>Of course, this is not the problem just good practice.<BR><BR>For next loops that "always" calculate the lbound and ubound of an array unnecessarily are bad practice. Store these values in variables and reference them instead. Much faster. Again, not the problem, just good practice.<BR><BR>Your variable naming convention suggests that you are referencing the files with URLs instead of regular file paths.<BR>I don&#039;t believe the file system object recognizes URLs or relative addressing as it is not part of the ASP intrinsics.<BR><BR>You may also want to check to see if the file exists before issuing a delete.<BR><BR>

Posting Permissions

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