Select to view content in your preferred language

Programmatically rename a table and a layer in VBA

493
3
06-12-2010 06:13 AM
DemetrisDemetriou
Emerging Contributor
Hi.
I would like to programmatically rename an existing dbf table or a feature layer based on its existing name. For example if the name is table.dbf the new name will be table1.dbf and then if the existing table name is table1.dbf rename it to table3.dbf and so on. Similalry, for a feauture class.

Any help please?
Thanks
Deme
0 Kudos
3 Replies
RuchiraWelikala
Regular Contributor
I think you'd have to parse the name and get the numeric value out of it.  Then do that numeric value + 1.  IDatasetName interface should offer some options for you!
0 Kudos
DemetrisDemetriou
Emerging Contributor
Thanks, but my problem is how to get the max index number (i.e.10,11 etc.) among a series of file names e.g. table10.dbf, table11.dbf etc.
Deme
0 Kudos
RuchiraWelikala
Regular Contributor
Hey Deme,
Yeah, so the parsing still stands.  Unless you know the naming convention of the tables.
Let's say there are 6 tables all together.  And the naming convention goes Table1, Table2, Table3 and so on...
You can simply count the number of tables and name the table based on that count.
But if the naming convention is not certain, then you have to parse the table name and get the number value out of it.  This will essentially be a loop that checks each table name.  Assign the numeric value to a variable each time the loop runs.  Then have an if statement that reassigns the variable to the numeric value if the new one value (of the tablename being tested) is larger than the old value.

Use regular expressions (if you're using .NET) to do the parsing.

Hopefully I understood your problem a little better (lol probably not though!)
0 Kudos