Illegal characters in filename

HMG en Español

Moderator: Rathinagiri

User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Illegal characters in filename

Post 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
There's nothing you can do that can't be done...
User avatar
mustafa
Posts: 1174
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Illegal characters in filename

Post by mustafa »

Hi Serge
See if it works with -> OLD_FILE.dbf ?
Greetings
Mustafa
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Illegal characters in filename

Post 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
There's nothing you can do that can't be done...
franco
Posts: 889
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Illegal characters in filename

Post 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.
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Illegal characters in filename

Post by serge_girard »

Renaming has happened outside a program and mostly not by me...

Serge
There's nothing you can do that can't be done...
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: Illegal characters in filename

Post 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.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
User avatar
AUGE_OHR
Posts: 2096
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Illegal characters in filename

Post 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

Code: Select all

USE OLD-FILE.dbf ALIAS "OLDFILE"
have fun
Jimmy
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Illegal characters in filename

Post 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
There's nothing you can do that can't be done...
User avatar
AUGE_OHR
Posts: 2096
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Illegal characters in filename

Post 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

Code: Select all

   USE 1234.DBF ALIAS "ONE"
p.s. this Way i can use Chinese Name of DBF
have fun
Jimmy
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Illegal characters in filename

Post by serge_girard »

Yes, I know! I replace cALIAS with 'xxxx'.

Serge
There's nothing you can do that can't be done...
Post Reply