[MI-L] Delete a table if it exists

904 views
Skip to first unread message

David Reid

unread,
May 3, 2010, 8:03:29 PM5/3/10
to mapi...@googlegroups.com
Greetings All,
 
I have a DOS batch file I call from an MBX to delete a temp table "IF EXISTS" this works nicely, but naturally causes the Mapinfo window to lose focus when the batch file is run.
 
How do I accomplish this with Mapbasic?
 
If EXIST "C:\Temp.TAB" Then
delete "C:\Temp.TAB"
EndIf
 
I may be going about this, wondering if I should "OPEN" the table if it exists, then "DROP" the table, but if there is no temp table, I don't want to recieve an error that it couldn't be found.
 
 
Thanks,
David

--
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To post to this group, send email to mapi...@googlegroups.com.
To unsubscribe from this group, send email to mapinfo-l+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mapinfo-l?hl=en.

David Reid

unread,
May 3, 2010, 8:10:08 PM5/3/10
to mapi...@googlegroups.com
Greetings All,
 
I have a DOS batch file using "IF EXIST" which I call from an MBX to delete a temp table that may or may not be there; this works nicely, but naturally causes the Mapinfo window to lose focus when the batch file is run.
 
Can I just do this directly with Mapbasic?
 
This doesn't compile, but something like:

If EXIST "C:\Temp.TAB" Then
delete "C:\Temp.TAB"
EndIf
 
Or should I "OPEN" the table if it exists, then "DROP" the table.
 
 
Thanks,
David

Javier Valencia

unread,
May 3, 2010, 8:18:47 PM5/3/10
to mapi...@googlegroups.com

I believe the MapBasic syntax is:

 

If FileExists(“C:\Temp.TAB”) THEN

            Open Table “C:\Temp”

            Drop table Temp

End IF

 

The “drop” command will delete the TAB file as well as its component. To use the “Drop” command, the table must already be open.

 

You can also use the command:

 

Kill “C:\Temp.TAB”

 

However this will only delete the TAB file and not its components.

 

Best regards,

 

Javier Valencia, PE

Principal

Valencia Technology Group, LLC

14315 S. Twilight Ln.

Suite #14

Olathe, Kansas 66062-4571

913-829-0888 Office

913-915-3137 Cell

913-649-2904 Fax

javier....@vtgonline.com

 

Confidentiality Notice

This electronic mail (including any attachments) may contain information that is privileged, confidential, and/or otherwise protected from disclosure to anyone other than its intended recipient(s). Any dissemination or use of this electronic email or its contents (including any attachments) by persons other than the intended recipient(s) is strictly prohibited. If you have received this message in error, please notify us immediately at 913-829-0888 or by reply email so that we may correct our internal records. Please then delete the original message (including any attachments) in its entirety.

 


David Reid

unread,
May 3, 2010, 9:30:30 PM5/3/10
to mapi...@googlegroups.com
Excellent, works as expected.
 
Never considered to search that as one word "fileexists" and never saw that in the help file until now!
 
Many thanks.
David
 



No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.814 / Virus Database: 271.1.1/2852 - Release Date: 05/03/10 13:27:00

Reply all
Reply to author
Forward
0 new messages