Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2004
    Posts
    96

    Unanswered: Problems using DeleteFile()

    Hi,
    I am trying to use DeleteFile() to remove images when a records relating is deleted in the DB.
    So far I can locate the file on the server using FileExists() but when I try to delete on my local IIS server (it is to go on host later) the script takes several minutes to execute, I don't get an error message but eventually IIS just crashes.
    Here is the script I am using:

    var fso= Server.CreateObject("Scripting.FileSystemObject");

    //collect the full file path and escape the \
    var file = Server.MapPath("\properties\\pop_images\\1.jpg")

    //check if the file exost and delete if it does
    if (fso.FileExists(file)==true)
    {

    fso.DeleteFile(file);
    Response.Write('file was found and has been deleted');

    }
    else
    {
    Response.Write('Sorry this file does not exist');
    }

    Thanking you for any help,
    olivier

  2. #2
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Correction in bold red

    Addition in bold black

    Code:
    var fso= Server.CreateObject("Scripting.FileSystemObject");
    
    //collect the full file path and escape the \
    var file = Server.MapPath("/properties/op_images/1.jpg")
    
    	//check if the file exost and delete if it does
    	if (fso.FileExists(file)==true)
    	{
                    
    	    Dim objFile
    	    Set objFile = fso.GetFile(file)
    	    objFile.Delete
    	    Set objFile = Nothing
    	    
    	    Response.Write('file was found and has been deleted');
    
    	} 
    	else
    	{
    	    Response.Write('Sorry this file does not exist');
    	}
    
    Set fso = Nothing
    That which does not kill me postpones the inevitable.

  3. #3
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Correction in bold red

    Addition in bold black

    Code:
    var fso= Server.CreateObject("Scripting.FileSystemObject");
    
    //collect the full file path and escape the \
    var file = Server.MapPath("/properties/op_images/1.jpg")
    
    	//check if the file exost and delete if it does
    	if (fso.FileExists(file)==true)
    	{
                    
    	    Dim objFile
    	    Set objFile = fso.GetFile(file)
    	    objFile.Delete
    	    Set objFile = Nothing
    	    
    	    Response.Write('file was found and has been deleted');
    
    	} 
    	else
    	{
    	    Response.Write('Sorry this file does not exist');
    	}
    
    Set fso = Nothing
    That which does not kill me postpones the inevitable.

  4. #4
    Join Date
    Aug 2004
    Posts
    96

    Getting error message when deleting file from folder

    hi,
    i have change the script following your advice, if I change the \ to a / the file is not found any more, however keeping the path as I had seems to work as the file is found.

    i have change the script to use the GetFile() method and this is working but when I add objFile.Delete I get the following message:

    Microsoft JScript runtime error '800a01b6'

    Object doesn't support this property or method

    on the main server that is, on my own iis it still gives me the same problem, could this be a problem of permissions not set properly?

    Thanking you for your help,
    Olivier

  5. #5
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Can you attach your code so we can take a look at what you're doing?
    That which does not kill me postpones the inevitable.

  6. #6
    Join Date
    Aug 2004
    Posts
    96
    Hello,
    here is the code I have below, it is in javascript:

    Code:
    var fso= Server.CreateObject("Scripting.FileSystemObject");
    
    //collect the full file path
    	
    	//this seems to be working OK as I get the message intended if the file is found
    	var file = Server.MapPath("\properties\\pop_images\\1.jpg")
    
    	//check if the file exist and delete if it does
    	if (fso.FileExists(file)==true)
    	{
    
    	
    	var objFile;
    	objFile = fso.GetFile(file);
    	
    	
    	//I am not getting an error and the script seems to be running fine with the above
    	//I start getting error messages when I add objFile.Delete;
    	objFile.Delete;
    	Response.Write('<p>file was found and has been deleted</P>');
    	
    
    	} 
    	else
    	{
    	Response.Write('Sorry this file does not exist');
    	}

  7. #7
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Doh.. that was my bad.. Java... Is Response.Write a valid method of SSJS? Are you sure it's not dieing there? I don't use SSJS, but you might try changing it to Document.Write
    That which does not kill me postpones the inevitable.

  8. #8
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    sholdn't it be...

    objFile.Delete();

  9. #9
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Nice rok.. I missed that.. good catch.. I was thinking VB and not SSJS, so I didn't include the parens...
    That which does not kill me postpones the inevitable.

  10. #10
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    hopefully it will help,... what is the actual error message??

  11. #11
    Join Date
    Aug 2004
    Posts
    96
    Hi,
    my own IIS is still blocking on it, doesn't give a error, just takes minutes to mve and eventually crash. Might be something local, I am waiting for my host to update the permissions and will et you know if it is working,
    Thanking you,
    olivier

  12. #12
    Join Date
    Aug 2004
    Posts
    96
    Finally got to test on the host server, it is working perfectly,
    Thank you very much,
    Olivier

Posting Permissions

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