If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Problems using DeleteFile()

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-27-04, 09:45
oliflorence oliflorence is offline
Registered User
 
Join Date: Aug 2004
Posts: 96
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
Reply With Quote
  #2 (permalink)  
Old 08-27-04, 10:37
Seppuku Seppuku is offline
Useless...
 
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.
Reply With Quote
  #3 (permalink)  
Old 08-27-04, 10:42
Seppuku Seppuku is offline
Useless...
 
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.
Reply With Quote
  #4 (permalink)  
Old 08-28-04, 05:35
oliflorence oliflorence is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 08-29-04, 15:52
Seppuku Seppuku is offline
Useless...
 
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.
Reply With Quote
  #6 (permalink)  
Old 08-30-04, 05:43
oliflorence oliflorence is offline
Registered User
 
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');
	}
Reply With Quote
  #7 (permalink)  
Old 08-30-04, 11:33
Seppuku Seppuku is offline
Useless...
 
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.
Reply With Quote
  #8 (permalink)  
Old 08-30-04, 21:13
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
sholdn't it be...

objFile.Delete();
Reply With Quote
  #9 (permalink)  
Old 08-30-04, 23:30
Seppuku Seppuku is offline
Useless...
 
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.
Reply With Quote
  #10 (permalink)  
Old 08-30-04, 23:42
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
hopefully it will help,... what is the actual error message??
Reply With Quote
  #11 (permalink)  
Old 09-03-04, 13:19
oliflorence oliflorence is offline
Registered User
 
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
Reply With Quote
  #12 (permalink)  
Old 09-08-04, 10:25
oliflorence oliflorence is offline
Registered User
 
Join Date: Aug 2004
Posts: 96
Finally got to test on the host server, it is working perfectly,
Thank you very much,
Olivier
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On