Re: Illegal characters in filename
Posted: Thu Nov 18, 2021 8:47 am
In case you want to open several DBFs with an unusual name in different areas this might be helpful:serge_girard wrote: ↑Thu Nov 18, 2021 8:12 am Thanks Jimmy,
That's the solution ! Because of the nature of my program the 'USE' is in a loop from a DIR function
and my USE is this construction:This now works perfect! Thanks again!Code: Select all
IF lOpenMode if cNew = 'NEW' USE ( cDatabase ) EXCLUSIVE NEW ALIAS cALIAS ELSE USE ( cDatabase ) EXCLUSIVE ALIAS cALIAS ENDIF ELSE if cNew = 'NEW' USE ( cDatabase ) SHARED NEW ALIAS cALIAS ELSE USE ( cDatabase ) SHARED ALIAS cALIAS ENDIF ENDIF IF !NETERR() RETURN ( TRUE ) ENDIF
Serge
Code: Select all
#include "hmg.ch"
Function Main
Local cDBF := "6. März - Wöchentliche Backup-Datei.dbf", i
IF !FILE(cDBF)
DBCREATE(cDBF, { {'ID','N',10,0} , {'NAME','C',30,0}, {'FLAG','C',3,0} } )
USE (cDBF) ALIAS (ValidAliasName (cDBF))
FOR i := 1 TO 2000
APPEND BLANK
REPLACE id WITH i
REPLACE name WITH "Name #" + AllTrim(Str(i))
REPLACE flag WITH IF (i % 3 = 0, "C", IF ( i % 2 = 0, "B", "A" ) )
NEXT i
CLOSE
ENDIF
USE (cDBF) ALIAS (ValidAliasName (cDBF)) SHARED
EDIT EXTENDED
Return
********************************************************
Function ValidAliasName ( cAliasName )
Local i, cValidAliasName := ""
cAliasName := hb_FNameName( cAliasName )
cAliasName := IF ( .NOT. IsAlpha( cAliasName ), "X", "") + cAliasName //alias must begins alpha
FOR i := 1 TO Len ( cAliasName )
cValidAliasName += IF ( Lower(SubStr( cAliasName, i, 1)) $ "abcdefghijklmnopqrstuvwxyz1234567890_", SubStr( cAliasName, i, 1), "_" )
NEXT i
RETURN cValidAliasName
*********************************************