Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting files 1

Status
Not open for further replies.

SlykFX

Programmer
Oct 12, 2002
76
0
0
GB
my db contains the locations of a load of files used in my project (all files are *.dat)
however i need to set it so that the user can delete the file from browser

my current script will delete the db record of the file, but i need to delete the file aswell
the files were all created on the server using the FS object.

i know the fileSystem object has a delete file function but i cant get it to actually delete the file. it reports that the file cannot be found.

what ive tried is:
(ive only included the working code for the function)

Code:
fileid = request.form("file")

set RS=Server.CreateObject("ADODB.recordset")
RS.Open "SELECT * FROM tblFiles WHERE fileid=" & fileid & "", conn, 2,2
	set fs=Server.CreateObject("Scripting.FileSystemObject")
	set f=fs.GetFile(RS.fields("fileLocation"))
	f.Delete
	RS.delete
RS.Close

i think the error lies in the line:
Code:
set f=fs.GetFile(RS.fields("fileLocation"))

any help will be much appreciated :)

I can't be bothered to have a sig!
 
Hey, I personally would eliminate the variable f and do the following

Code:
my db contains the locations of a load of files used in my project (all files are *.dat)
however i need to set it so that the user can delete the file from browser

my current script will delete the db record of the file, but i need to delete the file aswell
the files were all created on the server using the FS object.

i know the fileSystem object has a delete file function but i cant get it to actually delete the file.  it reports that the file cannot be found.

what ive tried is:
(ive only included the working code for the function)


fileid = request.form("file")

set RS=Server.CreateObject("ADODB.recordset")
RS.Open "SELECT * FROM tblFiles WHERE fileid=" & fileid & "", conn, 2,2
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    fs.DeleteFile(Server.MapPath(RS.fields("fileLocation")))
    RS.delete
RS.Close

This post is best viewed at 1024 x 768
 
thanks for that :)

its also solved my next question of checking if it exists :)

I can't be bothered to have a sig!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top