DeleteFile

I want to delete a photo when a user update his profile with a ne photo. It takes from the database the file name of the old photo, put in a session("oldPhoto") and update the database with the new one. Then to delete the old foto I've written the following code that is not working:

<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
path = "memberphotos/" & session("oldPhoto")
objFSO.DeleteFile(path)

response.redirect("myprofile.asp")
%>

Is there anyone could help me with this problem?

View Replies


ADVERTISEMENT

Regular Expressions In Fso.DeleteFile

Can I use regexps in fso.DeleteFile? I've found I can use a '?' and probably a '*' (although that seems a tad brutal) but I'm having trouble with expressions like ([a-z]|[0-9]-).

Am I wasting my time trying to get it to work (i.e. does it support them?) If so, how do I use them? Does it have its own quirky syntax or "standard" regexp? Every example I've found so far just mentions deleting something simple like *.txt.

For the record, I need to "tidy up" a directory full of images by deleting files whose names _don't_ contain particular text. It's quite convoluted and would be far easier if I could just go through each file one by one but hey. Here are the details:

1) I have a list of IDs in an array that I've read from a data source. This is the "current ID" list

2) I have a list of image filenames from a directory in another array. The image filenames contain an ID in them. There could be none, one or more images containing the same ID.

3) I look at each file in turn, extract the ID portion and add it to an array of "found" IDs - crucially, this array is only updated if the ID has not been seen before in another filename

4) I then step through this array and use Filter() to see if the ID is in the "current ID" list somewhere

5) If it is missing from the list, that ID is deemed "out of date" and all associated images containing that ID need to be deleted. Message to screen saying that ID has been deleted.

6) If it is in the list, just print a message saying it is "current" and move on.

I realise I could just step through each file and test it against the current ID list but then the output on-screen would be file-by-file and not ID-by-ID. The client doesn't care how many files there are; they don't even care about the underlying structure - they just point the browser to my script and it deletes the files, shows them which IDs have been removed and tells them how many IDs in total have been deleted.

If I went down that route I would have to keep a record of which IDs I've deleted and output the lot at the end instead of 1 by 1 as I go, which leaves the browser hanging for a while and doesn't give the client reassuring feedback as it ploughs through the directory adding the results to the screen row by row. Code:

View Replies View Related

FileSystemObject DeleteFile Method Question

I'm entirely new to using FSO's in ASP and I'm hoping someone can help me with a code sample or something to understand how to implement the DeleteFile method. I'm just trying to write a quick script that deletes the file "<%=Path%>"; where "Path" includes the full path and filename to delete.

View Replies View Related

DeleteFile Doesn't Work In Session_OnEnd???

I can successfully delete files using fso.DeleteFile when in an ASP
script. But in Session_OnEnd, where I'd *really* like to clean up
files, it appears that DeleteFile doesn't work. I've tried every
combination I could think of. I've verified the filespecs I'm using by
logging to a session log file.

BTW, I found out the hard way that I can't reference
Request.ServerVariables("APPL_PHYSICAL_PATH") from within
Session_OnEnd. I had to copy that to Session("AppPath") to keep it
around for the OnEnd event. Without that, ASP just bails out of OnEnd,
ignoring the remainder of the subroutine.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved