Page 1 of 2
Illegal characters in filename
Posted: Wed Nov 17, 2021 4:24 pm
by serge_girard
Hello,
Sometimes I rename a DBF file with a dash like: OLD-FILE.dbf
When accessing this file it will give this runtime error: Illegal characters in alias: OLD-FILE.
How can I avoid or suppress this error?
Serge
Re: Illegal characters in filename
Posted: Wed Nov 17, 2021 5:11 pm
by mustafa
Hi Serge
See if it works with -> OLD_FILE.dbf ?
Greetings
Mustafa
Re: Illegal characters in filename
Posted: Wed Nov 17, 2021 5:17 pm
by serge_girard
Hi Mustafa,
Yes, underscores are no problem!
Problem occurs when renamed by mistake with a dash (or maybe with some other illegal character).
So, I want to suppress "runtime error: Illegal characters in alias" by skipping these. Now I check if a dash is in the filename but there maybe others illegal chars....
Serge
Re: Illegal characters in filename
Posted: Wed Nov 17, 2021 6:33 pm
by franco
Hi Serge
Are you renaming inside a program or from (cmd or windows)
If from a program you could create a function to check for or remove illegal characters with chr() and asc() codes.
Re: Illegal characters in filename
Posted: Wed Nov 17, 2021 8:07 pm
by serge_girard
Renaming has happened outside a program and mostly not by me...
Serge
Re: Illegal characters in filename
Posted: Thu Nov 18, 2021 1:44 am
by Claudio Ricardo
Hi... i use this function to prevent invalid dbf field names:
Code: Select all
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Función ValidFieldName () Comprueba si el nombre ingresado es valido para campos DBF (retorna .T.)
// Creada por Claudio Ricardo 03/2021
Function ValidFieldName (cCadena)
LOCAL cValid := .T.
LOCAL i
If ValType (cCadena) <> "C"
Return .F.
EndIf
If SubStr (cCadena,1,1) $"0123456789" .OR. Len (cCadena) > 10
Return .F.
EndIf
For i = 1 To Len (cCadena)
If ! Lower ( SubStr (cCadena,i,1)) $"abcdefghijklmnopqrstuvwxyz0123456789_" // lista de caracteres permitidos
cValid := .F.
EndIf
Next
Return cValid
With small modification it is used for table names.
Re: Illegal characters in filename
Posted: Thu Nov 18, 2021 7:27 am
by AUGE_OHR
hi,
serge_girard wrote: ↑Wed Nov 17, 2021 4:24 pm
How can I avoid or suppress this error?
have you try
Re: Illegal characters in filename
Posted: Thu Nov 18, 2021 8:12 am
by serge_girard
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:
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
This now works perfect! Thanks again!
Serge
Re: Illegal characters in filename
Posted: Thu Nov 18, 2021 8:22 am
by AUGE_OHR
hi,
same is when try to open "1234.DBF"
it will crash while ALIAS() "1234" is not valid
but it work with
p.s. this Way i can use Chinese Name of DBF
Re: Illegal characters in filename
Posted: Thu Nov 18, 2021 8:32 am
by serge_girard
Yes, I know! I replace cALIAS with 'xxxx'.
Serge