Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2003, 12:26 AM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to brandon1974
Default DeleteFile(filespec) with relative path?

Hello everyone,

I have an access db with a table containing relative links to files. I need to use the file system object to delete the file from a directory and then delete the record from my db.

My hosting environment is shared Win2K Pro. Do I have to have the absolute path to the file I want to delete? or can I use the relative path. I keep getting "file not found errors"

Here is a sample of the code I'm using...

<%
    scid = BestLong(request.QueryString("scid"))
    dlid = BestLong(request.QueryString("dlid"))
    sc_name = DLookup("SC","SC","SCID=" & scid) 'gets name of sub category
    recordcount = DCount("*","SC","CCID=3") 'counts all records in db
    edit = request.QueryString("edit") = "yes"
    delete = request.QueryString("delete") = "yes"
    confirm = request.QueryString("confirm") = "yes"

    if confirm and scid > 0 and dlid > 0 then
    filelink = DLookup("DLLink","Downloads","DLID=" & dlid) 'gets relative path stored in table Downloads
 filename = Right(filelink, Len(filelink) - InStrRev(filelink, "/", -1, 1))
 filespec = "../gl/admin/documents/" & filename
 dim objFSO
 set objFSO = server.CreateObject("Scripting.FileSystemObject")
    response.Write(filespec)
 objFSO.DeleteFile(filespec)

        cmd = "delete from SCDownloads where DLID = " & dlid & ""
        on error resume next
        DoSQL MM_ConGL_STRING, cmd
        on error goto 0
        cmd = "delete from Downloads where DLID = " & dlid & ""
        on error resume next
        DoSQL MM_ConGL_STRING, cmd
        on error goto 0

        set objFSO = nothing

        response.Redirect "dsc_dld.asp?scid=" & scid
    end if
%>

Any ideas why that is returning a file not found error? Any insight appreciated.

Thanks,
Brandon

bT
 
Old July 19th, 2003, 04:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You'll need the entire path for the DeleteFile file to work. However, ASP comes with a handy MapPath function that will return the full path for a virtual file:

Code:
Dim FileName
Dim FullFileName
FileName = "/SubFolder/MyFile.ext"
FullFileName = Server.MapPath(FileName)
At this point, FullFileName will contain something like "c:\Inetpub\wwwroot\SubFolder\MyFile.ext"


HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Relative and Absolute Path question Johnger Pro Visual Basic 2005 1 September 8th, 2006 10:45 AM
iis cannot find images in relative path vhrao ASP.NET 1.x and 2.0 Application Design 4 November 30th, 2004 11:00 AM
Relative Path Connection String fangai Classic ASP Databases 1 October 3rd, 2003 02:37 AM
LDAP and Relative Path problem Dmitriy Pro VB 6 0 July 21st, 2003 12:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.