?
Solved

delete file using fso

Posted on 2003-02-22
8
Medium Priority
?
1,510 Views
Last Modified: 2007-12-19
I want to delete a file using fso object.
the file was uploaded with SAfileUp object.
I'm writing this command:

Set fso = CreateObject("Scripting.FileSystemObject")
delfile = Request("fileRef")
fso.DeleteFile(delfile)

delfile contains the whole path to the file
from some reason I get an error :"invalid procedure call or argument"
on this line : fso.DeleteFile(delfile)
I've tried to write like this : fso.DeleteFile("&delfile&")

but the error was "File not found"

what am I doing wrong??
thank you....
0
Comment
Question by:yaron9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Accepted Solution

by:
whammy earned 320 total points
ID: 7998414
You need to map the local path to the file in order for FSO to be able to delete it.

Try this:

delfile = Server.MapPath(Request("fileRef"))

If fso.FileExists(delfile) Then
   fso.DeleteFile(delfile)
Else
   ' Write the file path we're getting:
   Response.Write(delfile & " not found!" & "<br />" & vbCrLf)
End If
0
 

Expert Comment

by:jwalin
ID: 7998689
when you pass the value of fileRef .. That time you used Server.URLEncode(fileRef)

example:

<a href="http://server-name/abc.asp?fileRef=<%=Server.URLEncode(fileRef)%>">delete</a>

and then
Set fso = CreateObject("Scripting.FileSystemObject")
delfile = Request("fileRef")
fso.DeleteFile(delfile)

Jwalin
0
 

Author Comment

by:yaron9
ID: 7998945
try this:
Sub DeleteFile(fileName)
  Dim fso
  Set fso = CreateObject("Scripting.FileSystemObject")
  filepath = server.mappath(fileName)
  fso.DeleteFile  filePath
end Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Expert Comment

by:markhoy
ID: 7999550
to use fso you need a full file path ie d:\user\htdocs\file.asp

see ww.aspfaqs.com > File System Object

You also need the correct permissions under IIS for IUSR_machinename to delete the file.
0
 

Expert Comment

by:oceanASP
ID: 8002762
Here is what I found from http://www.sloppycode.net/fso/?m=56

DeleteFile
FSO.DeleteFile filename[,forceReadOnlyDelete]
 
Description
Deletes filename, which can contain wildcards (only the filename, not folder names).An error occurs if the filename is not found. [forceReadOnlyDelete] will force the file to be deleted if it's readonly.
 
<%
'***************** DeleteFile
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile "C:\afilename.*",true
' This deletes all files called "afilename", regardless of extension, and even if they are readonly files.
Set fso = Nothing
%>
0
 

Expert Comment

by:CleanupPing
ID: 9576947
yaron9:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 58

Expert Comment

by:Gary
ID: 9754335
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by whammy

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question