Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

legal VFP file names

Status
Not open for further replies.

tcloud1743

Technical User
Feb 15, 2011
2
0
1
US
I want to know what the file naming convention is for VFP. I can't find it anywhere.

What characters are allowed in file names and is there is any special rule for the first character of the name?

I have VFP-compatible tables generated by another application and some of the file names begin with exclamation marks -- e.g. "!!_000_find_gk.dbf", and VFP won't recognize or open those files.

thanks
 
There is no special convention for filenames in VFP. There are rules about what constitutes a legal filename, but these are not VFP-specific. Provided the name is legal in Windows, it will be acceptable in VFP.

Essentially, that means that the name can't contain any of the following characters:

[tt]\ / : * ? " < > |[/tt]

All other characters are legal, including those from the "upper ASCII" set (such as accented letters).

There are however conventions for file extentions, such as DBF for tables and PRG for programs. Is that what you had in mind?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
That is not my experience.
Example -- I have a file named "!_0_tmp_R.dbf"
- this file won't open when double-clicking on it
- it won't open from a .prg file with the "USE" command
- FILE('!_0_tmp_R.dbf') shows that it exists
It always gives the error pop-up "File 'c:\mypath\.dbc' does not exist"

I haven't tried other 'unusual' characters as a first letter, but an exclamation does not work for me. Other files begin with an underscore and that works okay.

This appears to just be for naming/opening tables as a FILETOSTR command will read the file. (I haven't check database names.)
 
Tcloud1743,

The problem is with the "!" and how VFP parses it while trying to use a table: it will interpret as a separator for database!table. VFP is complaining about not finding the database container (that would have to have an empty stem name...).

You may [tt]USE ?[/tt] the table from the command window, nonetheless (that is, opening it through the Open File dialog).
 
Atlopes has found the reason, it puzzles me, that the file doesn't open with double-clicking it, though.

I can reproduce that, what works is USE ? and then picking the DBF, but using the name in any way doesn't work, neither directly nor quoted, nor as name expression nor first stored in a variable.

Many other things are allowed, like spaces, the alias name will have underscores at places the file name has spaces.

You best have file names within the rules of alias names, see "Creating Visual FoxPro Names", that also tells file names themselves only have to apply to OS rules. Aside of the Exclamation mark, it seems.

Bye, Olaf.




Olaf Doschke Software Engineering
 
One more additional information to corroborate what we seem to have established, and another way to gain access to the table (it is, in fact, a derivation of the [tt]USE ?[/tt] method).

If you manage to create a [tt].dbc[/tt] (yes, precisely that, a database container with no name) and [tt]USE "!!_000_find_gk.dbf"[/tt], then VFP stops complaining about the missing [tt].dbc[/tt], and starts to error on [tt]!_000_find_gk.dbf[/tt] being not found. Notice that the first ! was skiped, and that now VFP is looking for the table.

We can have access to the table simply by inserting it into a form's DE - again, initially through the Open File dialog, but the table reference will persist in the form's definition and the table will always be available afterward.

 
Well, if the table is free you might add it to a dbc and then the dbc internal name can be something else than the file name and you can open it via that internal name, eg like this:

Code:
Create Table !test Free (id int)
Use
Create Database my.dbc
Add Table !test Name internalname
Use my!internalname
? Dbf()

If the DBF already is part of a DBC you might look into the DBC what's the internal table name.

But also look into my next post, if it isn't a VFP DBF you might harm the file structure when VFP tries to embed the DBC backlink into the DBF header.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Of course the nature of that name makes me wonder, if the creator had a strong reason to only use this in conjunction with a DBC. It's not really necessary, even if a developer opens a DBF before opening its DBC, the DBC will open and for example DBC events and triggers and table and field rule and default value expressions will be taken into account.

It might of course also be a non VFP DBF type, like dBase or Clipper table. Look into the first byte of the file, that tells the DBF file type, VFP comes with HExEdit in Tools, so you can open the DBF in VFPs own Hexeditor.

See
Bye, Olaf.

Olaf Doschke Software Engineering

PS: Just tested this: I created a DBC with DBC events and RETURN .F. in BeforeOpenTable also prevents opening a DBF without first opening the DBC. Trying to circumvent DBC events by direct USE some.dbf doesn't work. That doesn't mean it's impossible to turn off DBC events, so I'm not saying they are a strong mean of a protection mechanism. DBC event code is "open source" and a DBC can be modified. But you don't need to fear an INSERT INTO sometable.dbf instead of INSERT INTO somedbc!sometable doesn't make use of default values stored in the DBC or doesn't know long field names. Unsure why this naming was chosen, but it might be someone found this to prevent opening a DBF standalone. It's not necessary to protect against that this way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top