Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How do I check for the existence of a file?
Greetings,

I'm experimenting with an ASP page that reads data from a file name
that is passed to it as a parameter, as in this page, which works,
because the "good" file exists.

http://mazes.com/asp-maze/customize...d&firstname=jwk
(make "your name is an amazing asp.general programmer" mazes.

But when I try this page, with the "bad" file which does not exist, I'm
not succeeding:
http://mazes.com/asp-maze/customize...d&firstname=jwk

I've tried several solutions that I found by googling.

When I tried:
If (ns.FileExists(zfil)<>true) then ...

but even when I give it a valid name, it returns "False"

I've tried using
On Error Resume Next
set nq=ns.OpenTextFile(Server.MapPath(zfil),1,true)
if Err.Number <> 0 Then ...
On Error Goto 0

I have found a workaround. Here is what finally worked:

On Error Resume Next
set nq=ns.OpenTextFile(Server.MapPath(zfil),1,true)
if nq.AtEndOfStream=True Then
zfil=custompath&"customdatadefault.asp"
set nq=ns.OpenTextFile(Server.MapPath(zfil),1,true)
end if

But meanwhile, I'd love to hear how to check for the existence of a
file.

John


Report this thread to moderator Post Follow-up to this message
Old Post
www.MessageMazes.com
01-30-06 11:55 PM


Re: How do I check for the existence of a file?
You've got the key. You used MapPath to open the file. Why didn't you use it
to check for the file's existence?

If not ns.FileExists(server.mappath(zfil)) then

www.MessageMazes.com wrote:
> Greetings,
>
> I'm experimenting with an ASP page that reads data from a file name
> that is passed to it as a parameter, as in this page, which works,
> because the "good" file exists.
>
> http://mazes.com/asp-maze/customize...d&firstname=jwk
> (make "your name is an amazing asp.general programmer" mazes.
>
> But when I try this page, with the "bad" file which does not exist,
> I'm not succeeding:
> http://mazes.com/asp-maze/customize...d&firstname=jwk
>
> I've tried several solutions that I found by googling.
>
> When I tried:
> If (ns.FileExists(zfil)<>true) then ...
>
> but even when I give it a valid name, it returns "False"
>
> I've tried using
> On Error Resume Next
> set nq=ns.OpenTextFile(Server.MapPath(zfil),1,true)
> if Err.Number <> 0 Then ...
> On Error Goto 0
>
> I have found a workaround. Here is what finally worked:
>
> On Error Resume Next
> set nq=ns.OpenTextFile(Server.MapPath(zfil),1,true)
> if nq.AtEndOfStream=True Then
>   zfil=custompath&"customdatadefault.asp"
> set nq=ns.OpenTextFile(Server.MapPath(zfil),1,true)
> end if
>
> But meanwhile, I'd love to hear how to check for the existence of a
> file.
>
> John

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Report this thread to moderator Post Follow-up to this message
Old Post
Bob Barrows [MVP]
01-30-06 11:55 PM


Re: How do I check for the existence of a file?
Thanks, I'll try that.

Just did. It worked, even though I thought it didn't for a second. Had
to read the results twice.

Meanwhile, I figured out why the statement didn't generate an error.  I
had:

set nq=ns.OpenTextFile(Server.MapPath(zfil),1,true)

It should have been

set nq=ns.OpenTextFile(Server.MapPath(zfil),1,false)

I had told it to create the file if it didn't already exist, so of
course, it didn't generate an error. Now it does.

Thanks for all the help. This group is wonderful.

John


Report this thread to moderator Post Follow-up to this message
Old Post
www.MessageMazes.com
01-30-06 11:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

ASP archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:17 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.