Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: Checking if file exists in Delphi 1

60 views
Skip to first unread message

Mark de Vries

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
Hi,

I use Delphi 1 (Old, I know) and have a problem:
Before I load a file using the LoadFrom File method I want to check if it exists in the local directory. How can I do it?
If I'm right in later versions of Delphi you can use : if exist .... but not so in Delphi 1

Thanks in advance

Mark

--
M.J. de Vries
Delete GEEN.SPAM when replying


Paul J. Poirier

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
You "wrap" the call in a try...except...end block (which doesn't seem to
work quite like I expect) or ...

Here's what I use but note that you need the "I" compiler switch set to the
"old" way of doing things and the use of "string" (Pascal style, leading
length byte) as a parameter.

{$I+}
function file_exists(s : string) : boolean;
var
n : file;
f : boolean;
begin
assignfile(n,s);
reset(n);
f := ioresult = 0;
closefile(n);
file_exists := (ioresult = 0) and f;
end;
{$I-}

Mark de Vries wrote in message <6q6enh$rlt$1...@sun4000.casema.net>...

Felix Venniker

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
Why not use the function FileExists(const FileName: string): Boolean; ???
--
Felix Venniker,
Landmark Software Design Group B.V.,
The Netherlands.

fven...@landmarksdg.com

Paul J. Poirier <p...@istar.ca> wrote in article
<6SAx1.1$167....@NewsRead.Toronto.iSTAR.net>...

Ian A. Newby

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
Use If FileExists(<Filename>)...


In article <6q6enh$rlt$1...@sun4000.casema.net>, Mark de Vries <mdevries@GE
EN.SPAM.casema.net> writes


>Hi,
>
>I use Delphi 1 (Old, I know) and have a problem:
>Before I load a file using the LoadFrom File method I want to check if it exists
>in the local directory. How can I do it?
>If I'm right in later versions of Delphi you can use : if exist .... but not so
>in Delphi 1
>
>Thanks in advance
>
>Mark
>

--
Ian A. Newby

Ken White

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
Mark,

Just use FileExists()...

If FileExists(ExtractFilePath(Application.ExeName) + 'Test.Txt') then
{ File is there }

Works in all versions of Delphi.

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Mark de Vries wrote:
>
> Hi,
>
> I use Delphi 1 (Old, I know) and have a problem:
> Before I load a file using the LoadFrom File method I want to check if it exists in the local directory. How can I do it?
> If I'm right in later versions of Delphi you can use : if exist .... but not so in Delphi 1
>
> Thanks in advance
>
> Mark
>
> --

0 new messages