I want to cycle through a directory of .tab files and then run a process on the files. I found https://groups.google.com/forum/#!topic/mapinfo-l/reYENsRRziM but can't figure out how to define the path properly.
Once this is done I need it to alter and pack the tables.
Include "MapBasic.def"
Declare Sub Main
Sub Main
path_to_temp_tables = "Z:\projects\1_DSC24_Contours\Working\live_environment\5m\data\scratch"
'Run the Dos Command
Run program "Cmd.exe /c dir """+path_to_temp_tables+"*.TAB"" /b /w > """+path_to_temp_tables+"Liste.txt"""
'Registering a text file in MIpro
Register Table path_to_temp_tables+"Liste.txt" TYPE ASCII Delimiter 9 Charset "WindowsLatin1" Into path_to_temp_tables+"Liste.TAB"
'Opening the new TAB file based on your text file
Open Table path_to_temp_tables+"Liste.TAB" as Liste
'Alter Table "Liste" ( modify elev_text Char(4) ) Interactive
'Pack Table Liste.TAB Graphic Data
End Sub
Liste above should be the original name of the input file.
I have tried a trailing slash and putting the files in the same directory and then
path_to_temp_tables = ""
…but I get the same issue.
===== UPDATED SCRIPT ====
The dim removes the error but I only see the .txt file being created. How do I get it to cycle through the files and then on each file it should alter the table and pack it? See updated script.
Include "MapBasic.def"
Declare Sub Main
Sub Main
Dim path_to_temp_tables As String
path_to_temp_tables = "Z:\projects\1_DSC24_Contours\Working\live_environment\5m\data\scratch\"
'Run the Dos Command
Run program "Cmd.exe /c dir """+path_to_temp_tables+"*.TAB"" /b /w > """+path_to_temp_tables+"List.txt"""
'OPEN first file in List.txt
'Alter Table "XXX" ( modify elev_text Char(4) ) Interactive
'Pack Table XXX.TAB Graphic Data
'CONTINUE on next file
End Sub
Best Answer
First thing you need to do is either register the text file as a mapinfo table or, better in my opinion, just read the text file directly to get the table paths from it. Then, loop through the table paths and open, alter and pack each table. The below should do the job for you, just replace the text file path with the code you used to build your text file and pass the file's path to the
ReadTextFileToArray
sub.