Home > ASP Development > Delete file problem

Delete file problem



hi,



I have this code to delete a file from a folder



set fs = CreateObject("Scripting.FileSystemObject")

fs.DeleteFile("F:\Inetpub\WWWRoot\upfiles\" & getname, true)



but it gives an error saying



Microsoft VBScript compilation error '800a0414'



Cannot use parentheses when calling a Sub



any idea



todd

    
Guest
Best Answer


Quote:
Originally Posted by todd2006
yes mainfilext is a jpg image



its not a folder and i do see the image



todd




Okay, if mainfilext is a JPG image, then the filepath should be mainfilext.JPG and NOT just mainfilext. Where are you getting the value stored in the variable that is outputting the image name? Post the rest of your code... I have no idea what you are doing here.

Was this answer helpful ? Yes No   
Guest


Try:

Code:


set fs = CreateObject("Scripting.FileSystemObject")

strFileNameAndPath = "F:\Inetpub\WWWRoot\upfiles\" & getname

If fs.FileExists(strFileNameAndPath) Then
fs.DeleteFile(strFileNameAndPath, true)
End If



Was this answer helpful ? Yes No   
Guest


lewy,



tried ur code it still gives the same error



Microsoft VBScript compilation error '800a0414'



Cannot use parentheses when calling a Sub



todd

Was this answer helpful ? Yes No   
Guest


add the bolded lines and make sure it contains a file name


Code:


strFileNameAndPath = "F:\Inetpub\WWWRoot\upfiles\" & getname
response.Write(strFileNameAndPath)
response.End



Was this answer helpful ? Yes No   
Guest


lewy,



when i tried this code


Code:


If fs.FileExists(strFileNameAndPath) Then
fs.DeleteFile(Server.MapPath("F:\Inetpub\WWWRoot\upfiles\" & getname))
End If






i didnt get any errors but it didnt deleted the file in the folder



any idea



todd

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by todd2006
lewy,



when i tried this code


Code:


If fs.FileExists(strFileNameAndPath) Then
fs.DeleteFile(Server.MapPath("F:\Inetpub\WWWRoot\upfiles\" & getname))
End If






i didnt get any errors but it didnt deleted the file in the folder



any idea



todd




Why in the hell would you check the variable name if the file exists and then use an absolute path? That makes no sense.

Was this answer helpful ? Yes No   
Guest


response.Write that line out and you will see why it didn't delete anything


Code:


response.Write(Server.MapPath("F:\Inetpub\WWWRoot\upfiles\" & getname))



Was this answer helpful ? Yes No   
Guest


hi,



when i tried it like this i get this error



The Path parameter for the MapPath method must be a virtual path. A physical path was used.



any idea



todd





set fs = CreateObject("Scripting.FileSystemObject")

getname = Server.MapPath("F:\Inetpub\WWWRoot\upfiles\" & getname1)

Response.write getname



If fs.FileExists(getname) Then

Response.write "there"

fs.DeleteFile(getname)

End If

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by todd2006
hi,



when i tried it like this i get this error



The Path parameter for the MapPath method must be a virtual path. A physical path was used.



any idea



todd





set fs = CreateObject("Scripting.FileSystemObject")

getname = Server.MapPath("F:\Inetpub\WWWRoot\upfiles\" & getname1)

Response.write getname



If fs.FileExists(getname) Then

Response.write "there"

fs.DeleteFile(getname)

End If




Hmm, probably because Server.MapPath() FINDS the absolute path. You need to give it a relative path, more than likely something such as:




Code:


getName = Server.MapPath("\upfiles\" & getName1)
response.write getName
response.end






That SHOULD return the following:




Code:


F:\Inetpub\WWWRoot\upfiles\myGetNameValue



Was this answer helpful ? Yes No   
Guest


hi,



i even tried it like this




Code:


getname = Server.MapPath("/upfiles/" & getname1)




If IsFileExists(getname) = True Then
Response.Write "File exists"
objFSO.DeleteFile(getname)

Else
Response.Write "File does not exists"
End If

Function IsFileExists(byVal FileName)

If getname = "" Then
IsFileExists = False
Exit Function
End If

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists( getname ) = True Then
IsFileExists = True
Else
IsFileExists = False
End If

Set objFSO = Nothing
End Function






but it doesnt delete the old file



any idea



todd

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2010 by Infoqu. All rights reserved