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

error with File() function

135 views
Skip to first unread message

Stefan Haupt

unread,
Nov 2, 2012, 4:21:11 AM11/2/12
to
Hi all,

I noticed a problem with the file(cFile) function of xharbour. According to
the docs, it should search for cFile in the following order, if cFile does
not contain any directory information:
1. current dir
2. dir set with set default
3. dir set with set path

If set default is not set, it searches the current dir, but if set default
is set, it only searches this dir and not the current dir.

This small samples shows the error:

function Main ()

? "Testfile.txt", File ("testfile.txt") // found, ok
? "Testdir.txt", File ("testdir.txt") // not found, ok

SET DEFAULT TO ".\testdir" // subdir of the current dir

? "Testfile.txt", File ("testfile.txt") // not found, should be found
? "Testdir.txt", File ("testdir.txt") // found, ok

RETURN (nil)

Any hints ?

Stefan

dlzc

unread,
Nov 2, 2012, 10:06:06 AM11/2/12
to
Dear Stefan Haupt:

On Friday, November 2, 2012 1:18:54 AM UTC-7, Stefan Haupt wrote:
...
> I noticed a problem with the file(cFile)
> function of xharbour.

What version?

> According to the docs, it should search for
> cFile in the following order, if cFile does
> not contain any directory information:
>
> 1. current dir
>
> 2. dir set with set default
>
> 3. dir set with set path
...
> function Main ()
>
> ? "Testfile.txt", File ("testfile.txt") // found, ok
> ? "Testdir.txt", File ("testdir.txt") // not found, ok
>
> SET DEFAULT TO ".\testdir" // subdir of the current dir
>
> ? "Testfile.txt", File ("testfile.txt") // not found, should be found
> ? "Testdir.txt", File ("testdir.txt") // found, ok
>
> RETURN (nil)

What happens if you add
? curdir()
... before and after SET DEFAULT TO?

David A. Smith

Andi Jahja

unread,
Nov 2, 2012, 10:01:34 PM11/2/12
to
Hi David/Stefan:

The current version works as expected.

Andi

Stefan Haupt

unread,
Nov 5, 2012, 8:18:51 AM11/5/12
to
Am 02.11.2012 15:06, schrieb dlzc:


> What version?

build 1.2.1 Rev. 9411


>
> What happens if you add
> ? curdir()
> ... before and after SET DEFAULT TO?

Curdir() shows the correct dir


Stefan

Stefan Haupt

unread,
Nov 5, 2012, 8:27:00 AM11/5/12
to
Am 03.11.2012 03:01, schrieb Andi Jahja:
> Hi David/Stefan:
>
> The current version works as expected.
>
> Andi
>

Thanks, but I do not know if the last version is compatible with Fivewin.
Was there a change in pcode ?

Stefan

Enrico Maria Giordano

unread,
Nov 5, 2012, 8:29:49 AM11/5/12
to
> Thanks, but I do not know if the last version is compatible with Fivewin.
> Was there a change in pcode ?

Not recently (years ago).

EMG

--
EMAG Software Homepage: http://www.emagsoftware.it
The EMG's ZX-Spectrum Page: http://www.emagsoftware.it/spectrum
The Best of Spectrum Games: http://www.emagsoftware.it/tbosg
The EMG Music page: http://www.emagsoftware.it/emgmusic


Stefan Haupt

unread,
Nov 6, 2012, 9:43:34 AM11/6/12
to
Hi Andy,

I just downloaded the last Version from Mel (xHarbour 1.2.3 Rev.9804)

It愀 still not working, after setting the path with set default, the file
in the current dir is not found.

CurDir() shows the correct directory.

Sample code:
//---------------------------------------------------------------
#include "Fivewin.ch"

function Main ()

local lF

? Set (_SET_DEFAULT), CurDir (),"Testfile.txt", File ("testfile.txt") // found
? "Testdir.txt", File ("testdir.txt") // not found


SET DEFAULT TO ".\testdir"

? Set (_SET_DEFAULT), CurDir (),"Testfile.txt", File ("testfile.txt") //
not found
? Set (_SET_DEFAULT), CurDir (),"Testdir.txt", File ("testdir.txt") // found

RETURN (nil)
//-------------------------------------------------------------------

Please, could you check this.

BTW, if set default is not set and only set path is set, everything is
working fine. If both are set the function fails.

Thanks

Stefan

Stefan Haupt

unread,
Nov 6, 2012, 9:45:31 AM11/6/12
to
I forgot

I´m using Borland 5.82

Andi Jahja

unread,
Nov 6, 2012, 10:35:37 AM11/6/12
to
Sorry, I still cannot catch your error :-)
FILE() function in xHarbour respects SET DEFAULT setting.
Can you please rewrite your sample showing the result _and_ the result
that you are expecting? I'll try to simulate it here.

Andi

dlzc

unread,
Nov 6, 2012, 10:57:55 AM11/6/12
to
Dear Andi Jahja:

On Tuesday, November 6, 2012 8:35:45 AM UTC-7, Andi Jahja wrote:
> Sorry, I still cannot catch your error :-)
> FILE() function in xHarbour respects SET
> DEFAULT setting.

It ignores checking the current directory, at any point, before (or after) its checks DEFAULT, and PATH.

> Can you please rewrite your sample showing
> the result _and_ the result that you are
> expecting? I'll try to simulate it here.

His original code shows this:

<QUOTE>
function Main ()

? "Testfile.txt", File ("testfile.txt") // found, ok
? "Testdir.txt", File ("testdir.txt") // not found, ok

SET DEFAULT TO ".\testdir" // subdir of the current dir

? "Testfile.txt", File ("testfile.txt") // not found, should be found
? "Testdir.txt", File ("testdir.txt") // found, ok

RETURN (nil)
<END QUOTE>

David A. Smith

Andi Jahja

unread,
Nov 7, 2012, 8:51:52 AM11/7/12
to
Hi David,

Many thanks for making it clear.

On Tue, 6 Nov 2012 07:57:55 -0800 (PST), dlzc <dl...@cox.net> wrote:

>Dear Andi Jahja:
>
>On Tuesday, November 6, 2012 8:35:45 AM UTC-7, Andi Jahja wrote:
>> Sorry, I still cannot catch your error :-)
>> FILE() function in xHarbour respects SET
>> DEFAULT setting.
>
>It ignores checking the current directory, at any point, before (or after) its checks DEFAULT, and PATH.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It is exactly Clipper behaviour, the same as applied in xHarbour.

>> Can you please rewrite your sample showing
>> the result _and_ the result that you are
>> expecting? I'll try to simulate it here.
>
>His original code shows this:
>
><QUOTE>
>function Main ()
>
> ? "Testfile.txt", File ("testfile.txt") // found, ok
> ? "Testdir.txt", File ("testdir.txt") // not found, ok
>
> SET DEFAULT TO ".\testdir" // subdir of the current dir
>
> ? "Testfile.txt", File ("testfile.txt") // not found, should be found
> ? "Testdir.txt", File ("testdir.txt") // found, ok
>
> RETURN (nil)
><END QUOTE>

This results of this snippet is as expected. Please try to compile
with Clipper. If the results are different with xHarbour, I'll go
digging the codes :-)

Andi

dlzc

unread,
Nov 7, 2012, 9:42:12 PM11/7/12
to
Dear Andi Jaha:

On Wednesday, November 7, 2012 6:51:54 AM UTC-7, Andi Jahja wrote:
...
> > It ignores checking the current directory, at
> > any point, before (or after) its checks
> > DEFAULT, and PATH.
>
>
> It is exactly Clipper behaviour, the same as
> applied in xHarbour.

I concur. Clipper 5.01 (don't have 5.2 or 5.3) shows this exact behavior, despite the documentation for Clipper.

...
> This results of this snippet is as expected.

Not as *documented*, however. We either need to correct the documentation, or make the language do what the documentation says it should do.

> Please try to compile with Clipper. If the
> results are different with xHarbour, I'll go
> digging the codes :-)

I'm sorry it always has to be you...

David A. Smith

Stefan Haupt

unread,
Nov 8, 2012, 3:00:21 AM11/8/12
to
Am 08.11.2012 03:42, schrieb dlzc:
> Dear Andi Jaha:
>
> On Wednesday, November 7, 2012 6:51:54 AM UTC-7, Andi Jahja wrote:
> ...
>>> It ignores checking the current directory, at
>>> any point, before (or after) its checks
>>> DEFAULT, and PATH.
>>
>>
>> It is exactly Clipper behaviour, the same as
>> applied in xHarbour.
>
> I concur. Clipper 5.01 (don't have 5.2 or 5.3) shows this exact behavior, despite the documentation for Clipper.
>
> ...
>> This results of this snippet is as expected.
>
> Not as *documented*, however. We either need to correct the documentation, or make the language do what the documentation says it should do.
>

I agree, but I would prefer to correct the language, not the docs. I think,
bugs in clipper shouldn´t be ported to xharbour.

thanks

Stefan


Andi Jahja

unread,
Nov 8, 2012, 6:32:10 AM11/8/12
to
Hello Stefan,

IMO, it is not a bug, but an intended behavior. Below is a copy-paste
from Clipper 5.2e NG file:

----- 8< -----

FILE()
Determine if files exist in the CA-Clipper default directory or path
------------------------------------------------------------------------------
Syntax

FILE(<cFilespec>) --> lExists

Arguments

<cFilespec> is in the current CA-Clipper default directory and
path.
It is a standard file specification that can include the wildcard
characters * and ? as well as a drive and path reference.
Explicit references to a file must also include an extension.

Returns

FILE() returns true (.T.) if there is a match for any file
matching the <cFilespec> pattern; otherwise, it returns false
(.F.).

Description

FILE() is an environment function that determines whether any
file matching a file specification pattern is found. FILE()
searches the specified directory if a path is explicitly
specified.

If a path is not specified, FILE() searches the current
CA-Clipper default directory and then the CA-Clipper path. In no
case is the DOS path searched. Note also that FILE() does not
recognize hidden or system files in its search.

Examples

� In this example FILE() attempts to find Sales.dbf in other
than the current CA-Clipper default:

? FILE("Sales.dbf") // Result: .F.
? FILE("\APPS\DBF\Sales.dbf") // Result: .T.
//
SET PATH TO \APPS\DBF
? FILE("Sales.dbf") // Result: .T.
//
SET PATH TO
SET DEFAULT TO \APPS\DBF\
? FILE("Sales.dbf") // Result: .T.
? FILE("*.dbf") // Result: .T.

Files: Library is CLIPPER.LIB.

----- 8< -----

Reading the Description part, it is very clear that it is intended.

Andi

Stefan Haupt

unread,
Nov 8, 2012, 8:34:54 AM11/8/12
to
Hi Andy,

ok, thanks for clarification.

Stefan

dlzc

unread,
Nov 8, 2012, 8:56:15 AM11/8/12
to
Dear Andi Jahja:

On Thursday, November 8, 2012 4:32:13 AM UTC-7, Andi Jahja wrote:
...
> Reading the Description part, it is very clear
> that it is intended.

OUR online docs say (this morning):
<QUOTE>
The file() function is used to check if a file exists that matches the file specification <cFileSpec>. When <cFileSpec> does not contain directory information, the function searches directories in the following order:

1.
the current directory.

2.
the directory set with SET DEFAULT .

3.
the directories listed in the SET PATH setting.

Directories defined with environment variables of the operating system are not searched for <cFileSpec>. In addition, hidden or system files are not recognized by file().
<END QUOTE>

So we need to get the docs corrected, removing "step 1". Because to do that, breaks Clipper compatibility.

David A. Smith

Andi Jahja

unread,
Nov 8, 2012, 9:33:34 AM11/8/12
to
Dear David,

Yes, it'll be a wise action to get the doc modified.

Andi
0 new messages