>>> Now I am looking for a wildcard that could replace this index number.
You can use the -1 value for this purpose or not point the WndIndex parameter at all:
w= p.Window("SunAwtDialog", "Select a Folder")
w= p.Window("SunAwtDialog", "Select a Folder", -1)
BTW, TestComplete adds indexes to windows only if there are several windows with the same WndClass and WndCaption properties among the children of the process. Is this normal when several "Select a Folder" windows exist in your application?
If you have several windows with the same WndClass and WndCaption parameters and you call the Window function without specifying the WndIndex parameter, the "Ambiguous Recognition" error will occur and the corresponding error message will be posted to the Log. In this case you should use some additional logic in your script to find out which window is the desired one. For example, you can use the ChildCount, Left, Top, etc. window properties to find the desired window among others. You can also use the Sys.ActiveWindow() function: if the "Select a Folder" window becomes active when you open it from script, you can use the Sys.ActiveWindow() function to get a reference to this widow.