Function FILE(...)

Postby E. Bartzokas » Sun Jul 16, 2006 5:30 am

EnricoMaria wrote:
Badara Thiam wrote:Evans,

Did you try to create CON.BMP from Explorer? If not, please do it and you will find that Windows doesn't allow to create a file with that name.

EMG


Enrico,
We are probably making an issue here for no apparent reason.
The question is not if Windows allows creating a file with the name "CON.*", but rather searching why Function FILE(...) does not behave the same way in the 16-bit and 32-bit.

The 16-bit returns .F. and the 32-bit returns .T.., so why is this happening and my next question is who's function is FILE() ? I didn't find anything in the provided source code that comes with FW/FWH for this function.

Therefore, perhaps some of the big gurus can tell us how this function is called, and where it belongs (xHarbour or FWH) ?.

It doesn't matter if I/we use a windows' reserved name, but it's the return value that matters. It would be more appropriate to return the same value as the equivalent 16-bit, and DOS-Clipper, rather than giving me this surprise, realizing that this function was the mother of a nice "crash" of my program, which was trying to resize a bitmap to fit inside a box on a paycheck! The program fell in an endless loop just because the function FILE() returned .T. for a non existing file....

Who would even expect that this function would not function properly (when it did in Clipper/FW), and check this specific return value, instead of spending several hours checking the rest of the code, to find where it fails... So this was my problem, that I didn't even suspect that FILE() caused the problem.

Thank You All for spending so many hours to reply to this email. I still think that I did not get the proper reply to this post though.... My question once again is why is this difference between 16-32 bit ?

Kind reagards to all
Evans
User avatar
E. Bartzokas
 
Posts: 114
Joined: Tue Feb 14, 2006 8:13 am
Location: Corinth, Greece

Postby Enrico Maria Giordano » Sun Jul 16, 2006 7:04 am

The issue is simple and totally related to the file system. If you try to create the file CON.BMP from Explorer you will get the message that the file already exists. Therefore there is nothing that [x]Harbour or any other language can do to avoid the problem. The file CON.BMP definitely does exist. Just try for yourself.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Badara Thiam » Sun Jul 16, 2006 9:54 am

The same function modified to support asterix ("?" and "*")
like File()

Code: Select all  Expand view
******************
FUNCTION FileExist(cFichier, lCacheSyst)
******************
* Creation le 15/07/2006
* Derniere modification le 16/07/2006
* Auteur Badara Thiam
LOCAL nAttributs
LOCAL nCount := 1
LOCAL X
LOCAL cSepare := ""
LOCAL cFichierTmp := ""

IF "\" $ cFichier
ELSEIF !EMPTY( SET(_SET_DEFAULT) )
* Recherche dans le répertoire par défaut de clipper (SET DEFAULT TO)
  cFichier := TRIM(SET(_SET_DEFAULT)) + "\" + cFichier
ELSEIF !EMPTY( SET(_SET_PATH) )
* Recherche dans le(s) répertoire(s) du path de clipper (SET PATH TO)
  nCount := LEN( SET(_SET_PATH) ) - LEN( STRTRAN(SET(_SET_PATH),",","") ) + 1
  IF nCount = 1
    nCount := LEN( SET(_SET_PATH) ) - LEN( STRTRAN(SET(_SET_PATH),";","") ) + 1
    IF nCount = 1
      cFichier := TRIM(SET(_SET_PATH)) + "\" + cFichier
    ELSE
      cSepare := ";"
    ENDIF
  ELSE
    cSepare := ","
  ENDIF
ENDIF

FOR X := 1 TO nCount
  IF nCount = 1
    FileExist2(@cFichier, @cFichierTmp, @lCacheSyst)
  ELSE
    FileExist2(ALLTRIM( TOKEN(SET(_SET_PATH), cSepare, nCount) ) + "\" + cFichier, @cFichierTmp, @lCacheSyst)
  ENDIF
  nAttributs := GetFileAttributes( cFichierTmp )
  IF cFichierTmp != ""
    IF nAttributs >= 0 .AND. ( nAttributs % 32 ) < IIF(EMPTY(lCacheSyst), 2, 8)
      RETURN .T.
    ENDIF
  ENDIF
NEXT X
RETURN .F.

*******************
FUNCTION FileExist2(cFichier, cFichierTmp, lCacheSyst)
*******************
LOCAL aFichierTmp
LOCAL Posi
IF "*" $ cFichier .OR. "?" $ cFichier
  aFichierTmp := DIRECTORY(cFichier, IIF(EMPTY(lCacheSyst), NIL, "HS"))
  IF !EMPTY(aFichierTmp)
    Posi := ASCAN( aFichierTmp, { ¦a¦ !EMPTY( STRTRAN(a[1], ".", "") ) } )
    IF Posi > 0
      cFichierTmp := LEFT(cFichier, RAT("\",cFichier)) + aFichierTmp[Posi][1]
    ELSE
      cFichierTmp := ""
    ENDIF
  ELSE
    cFichierTmp := ""
  ENDIF
ELSE
  cFichierTmp := cFichier
ENDIF
RETURN NIL


Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
 
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France

Postby Badara Thiam » Sun Jul 16, 2006 10:00 am

The 16-bit returns .F. and the 32-bit returns .T.


Not for me : the 16-bit return .T., with FW and with
pure Clipper DOS (Clipper 5.3b + Clipper Tools 3).

Regards
Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
 
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests