Renaming certain columns in every file the working directory

6 posts / 0 new
Last post
Joined: 01/16/2020 - 06:30
Renaming certain columns in every file the working directory

I'd like to rename the field names that fits a certain list in every file of my project.
For example:
Some files in my project have columns named "YEAR", "DATE", "BALANCE" and they have to be renamed into "YEAR_1", "DATE_NEW", "BALANCE_X". So they don't get the same extension but every field name has a new field name without some logic behind it.
It would be nice, if one could have a dialogue box with every .IMD file in the project where you can check which files should be scanned for old field names and replace them with the new ones.
To rename them in a specific file is easy as you can simply record a macro and just replace the file name. But how can I automatically do it for every file?
Thank you very much in advance.
I'm using IDEA 10.

Brian Element's picture
Brian Element
Joined: 07/11/2012 - 19:57

HI ferby09 and welcome to the site.

There is a script that will do something like you want, adding a prefix or suffix to each field ( .  I am curious to understand what you are looking for, any chance you can flesh it out with an example so I can understand it better.



Joined: 01/16/2020 - 06:30

Thank you for your answer.
Unfortunately your script isn't the feature I'm looking for.
The case is that I've got old files from IDEA 8 which contain standardized field names possibly among others, which are not relevant for this script. Now I've got IDEA 10 and the standardized field names changed in the company. So when I convert old IDEA 8 files to IDEA 10 I can't use the new macros as they rely on the new names. The type of values didn't change, it's just a new name.
But these new names don't follow a prefix or suffix so they have to be identified and replaced by name in every file that I convert.
The script for a single file and field name would look like this.
Sub Main
   Call ModifyField()
End Sub
Function ModifyField
   Set db = Client.OpenDatabase("file.IMD")
   Set task = db.TableManagement
   Set field = db.TableDef.NewField
   field.Name = "BO_YE"
   field.Description = "Booking year"
   field.Type = WI_CHAR_FIELD
   field.Equation =""
   field.Length = 4
   task.ReplaceField "YEAR", field
   Set task = Nothing
   Set db = Nothing
   Set field = Nothing
End Function
This is what the macro records when I change the field name.
The fact that it's not a numeric field doesn't matter.

Joined: 02/13/2019 - 08:41

If you want to rename the fields of all files within a folder you should look on the Dir() object.

Joined: 01/16/2020 - 06:30

Thank you for your hint. 
This function is looking good but there is still alot missing to get my desired result I guess.
I can use Dir() to get all names in my working directory with .IMD but what next?
The function should be something like:
- get the quantity and names of file with .IMD in the working directory
- using something like "do while" to rename the field names in each file until every file has been checked
But how do I use a list of file names to use them in a loop and replace them with the file name in my second post?

Joined: 02/13/2019 - 08:41

The example below with some more comments you will find in IDEA's language browser:

Sub Main
    LogFiles = Dir("C:\Windows\*.LOG")
    FileList = LogFiles
    Do While LogFiles <> ""
         LogFiles = Dir
         If Len(LogFiles) > 1 Then
        End If
End Sub