I have a task where I need to take the file name (no extension) of a MapInfo file and place it into a new field within its attribute table.

I would normally use Arcpy to do something similar, but I am unfamiliar with MapInfo and have a basic understanding of QGIS.

The reason behind this task is because we will merge all the MapInfo files and will need a reference to each of the features. We have a few hundred of these files so automation is preferred.

1 Answer 1


MapBasic, the scripting language of MapInfo Pro, has a number of functions/statements that can be helpful for you:

  • TableInfo(): can be used to get basic information about an open table
  • PathToTableName$(): can extract the table name, as MapInfo Pro sees it, from a file path
  • PathToFileName$(): can extract a filename with extension from a file path
  • Update: can be used to update a column in a table
  • Left$(): can extract part of a string
  • Len(): can tell you the length of a string

So to update a column in a table with the file name of the table without extension, you could do the following:

  1. Open the tables that you need to update
  2. Run this statement to add a new column to the table. If you already have the column you need to update, go to step 3

    Alter Table TableInfo(NumTables(), 1) (Add TABFILENAME Char(254))
  3. Run this statements to update the TABFILENAME column in the table with the path of the table:

    Update TableInfo(NumTables(), 1) 
        Set TABFILENAME = Left$(TableInfo(NumTables(), 19), Len(TableInfo(NumTables(), 19)) - 4)  
  4. Run this statement to save the changes to the table:

    Commit Table TableInfo(NumTables(), 1)
  5. Run this statement to close the table:

    Close Table TableInfo(NumTables(), 1)

Now, if you write all the statements above into the MapBasic window in MapInfo Pro, highlight all the lines and hit Enter, you can continue hitting Enter until all the tables have been closed (and so been updated).

You find the MapBasic window via the Options menu in MapInfo Pro 32 bit and via the Windows Gallery on the HOME tab in MapInfo Pro 64 bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.