Replacing the module name in a folder with another name via DXL scripting

Hello,

I need to replace the module name in a folder with the other name.

Can any one please help me out.

Thanks ,

Shri


KBSri - Wed Sep 18 08:27:54 EDT 2013

Re: Replacing the module name in a folder with another name via DXL scripting
llandale - Wed Sep 18 12:50:58 EDT 2013

The thing to rename must be CLOSED; if inside a folder/module you may not rename it.

This should do it:

string  ErrMess = rename("/MyProject/MyFolder/MyModule_NameOld","NameNew","Description_New") 

 Edit: Oops: string  ErrMess = rename(module("/MyProject/MyFolder/MyModule_NameOld"),"NameNew","Description_New") 

-Louie

Re: Replacing the module name in a folder with another name via DXL scripting
KBSri - Wed Sep 18 13:23:26 EDT 2013

llandale - Wed Sep 18 12:50:58 EDT 2013

The thing to rename must be CLOSED; if inside a folder/module you may not rename it.

This should do it:

string  ErrMess = rename("/MyProject/MyFolder/MyModule_NameOld","NameNew","Description_New") 

 Edit: Oops: string  ErrMess = rename(module("/MyProject/MyFolder/MyModule_NameOld"),"NameNew","Description_New") 

-Louie

Thanks Louie.I should have defined my requirement more clearer.

I should replace the module names in a folder(Folder has number of modules).

Eg: Consider the module names inside a folder: FL_Shri_Airinfo

FL_Shri_Infotainment

I should replace all the module names containing "Shri" with the word "Adv" in all the modules.

Output of the new module names should be : FL_Adv_Airinfo

FL_Adv_Infotainment

Please guide me.

Thanks in advance.

 

 

Re: Replacing the module name in a folder with another name via DXL scripting
llandale - Wed Sep 18 13:52:28 EDT 2013

KBSri - Wed Sep 18 13:23:26 EDT 2013

Thanks Louie.I should have defined my requirement more clearer.

I should replace the module names in a folder(Folder has number of modules).

Eg: Consider the module names inside a folder: FL_Shri_Airinfo

FL_Shri_Infotainment

I should replace all the module names containing "Shri" with the word "Adv" in all the modules.

Output of the new module names should be : FL_Adv_Airinfo

FL_Adv_Infotainment

Please guide me.

Thanks in advance.

 

 

So if the module name contains exactly "_Shri_" then replace that part with "_Adv_".  Let me scribble a function, you may need to debug a little

  • Regexp reFromField = regexp2("(.*)(_Shri_)(.*)")
  • string ToField = "_Adv_"
  •  
  • string ConvertName(string in_Name)
  • {  // When the naame contains from field replace it with the to field
  •    // return null when there is no change
  •    if (reFromField in_Name) //
  •   then return(in_Name[match 1] ToField in_Name[match 3])  //build new string
  •   else return("")
  • }  // end ConvertName()

-Louie

Re: Replacing the module name in a folder with another name via DXL scripting
KBSri - Thu Sep 19 02:45:23 EDT 2013

llandale - Wed Sep 18 13:52:28 EDT 2013

So if the module name contains exactly "_Shri_" then replace that part with "_Adv_".  Let me scribble a function, you may need to debug a little

  • Regexp reFromField = regexp2("(.*)(_Shri_)(.*)")
  • string ToField = "_Adv_"
  •  
  • string ConvertName(string in_Name)
  • {  // When the naame contains from field replace it with the to field
  •    // return null when there is no change
  •    if (reFromField in_Name) //
  •   then return(in_Name[match 1] ToField in_Name[match 3])  //build new string
  •   else return("")
  • }  // end ConvertName()

-Louie

Hello Louie,

I tried creating buffer using you sample function, but it is not working.

I am getting syntax error in line :  then return(in_Name[match 1] ToField in_Name[match 3])  //build new string

Here is my code:

string strFolder = "Test_FROP/First"

Folder delFold = folder(strFolder)
Module modHandle
Item deletedItem

for deletedItem in delFold do
{
    print "The Existing module Name in the current folder\n"
    print name(deletedItem)"\n"

    Regexp reFromField = regexp2("(.*)(_Shri_)(.*)")
    string ToField = "_Adv_"
    Buffer bufModName = create

    string ConvertName(string in_Name)
    {  
        // When the naame contains from field replace it with the to field
        // return null when there is no change
        bufModName = (deletedItem,in_Name)
        if (reFromField bufModName)
                then return(in_Name[match 1] ToField in_Name[match 3])  //build new string
        else return("")
    }  // end ConvertName()
}
Please guide me.

Thanks,

Shri

 

Re: Replacing the module name in a folder with another name via DXL scripting
KBSri - Thu Sep 19 03:46:41 EDT 2013

llandale - Wed Sep 18 13:52:28 EDT 2013

So if the module name contains exactly "_Shri_" then replace that part with "_Adv_".  Let me scribble a function, you may need to debug a little

  • Regexp reFromField = regexp2("(.*)(_Shri_)(.*)")
  • string ToField = "_Adv_"
  •  
  • string ConvertName(string in_Name)
  • {  // When the naame contains from field replace it with the to field
  •    // return null when there is no change
  •    if (reFromField in_Name) //
  •   then return(in_Name[match 1] ToField in_Name[match 3])  //build new string
  •   else return("")
  • }  // end ConvertName()

-Louie

Hello Louie,

Jus had a second thought on this. Why not use

rename(item)

Please guide me.

Thanks & Regards,

Shri

Re: Replacing the module name in a folder with another name via DXL scripting
llandale - Thu Sep 19 12:33:17 EDT 2013

KBSri - Thu Sep 19 03:46:41 EDT 2013

Hello Louie,

Jus had a second thought on this. Why not use

rename(item)

Please guide me.

Thanks & Regards,

Shri

That could work for the actual rename.  As per 3rd post, the question was really how he finds names of modules that he WANTS to change.

Re: Replacing the module name in a folder with another name via DXL scripting
llandale - Thu Sep 19 12:35:46 EDT 2013

KBSri - Thu Sep 19 02:45:23 EDT 2013

Hello Louie,

I tried creating buffer using you sample function, but it is not working.

I am getting syntax error in line :  then return(in_Name[match 1] ToField in_Name[match 3])  //build new string

Here is my code:

string strFolder = "Test_FROP/First"

Folder delFold = folder(strFolder)
Module modHandle
Item deletedItem

for deletedItem in delFold do
{
    print "The Existing module Name in the current folder\n"
    print name(deletedItem)"\n"

    Regexp reFromField = regexp2("(.*)(_Shri_)(.*)")
    string ToField = "_Adv_"
    Buffer bufModName = create

    string ConvertName(string in_Name)
    {  
        // When the naame contains from field replace it with the to field
        // return null when there is no change
        bufModName = (deletedItem,in_Name)
        if (reFromField bufModName)
                then return(in_Name[match 1] ToField in_Name[match 3])  //build new string
        else return("")
    }  // end ConvertName()
}
Please guide me.

Thanks,

Shri

 

I just scribbbled the function.  Add declarations and put the function at the top of the code, and then call it.

Re: Replacing the module name in a folder with another name via DXL scripting
KBSri - Fri Sep 20 04:31:38 EDT 2013

llandale - Thu Sep 19 12:33:17 EDT 2013

That could work for the actual rename.  As per 3rd post, the question was really how he finds names of modules that he WANTS to change.

Hi Louie,

I think actual rename is something which will work better.

I tried the belowcode in DXL to rename the module in a folder to be renamed.


string strFolder = "/Test_FROP/First"

Folder delFold = folder(strFolder)

Item deletedItem

string strModName = "FeatureRollout_Adv_Adapt"

for deletedItem in delFold do
{
    rename(delFold,strModName,"Adv")
}
print "Success\n"

But it is renaming the module at all. Please help me out.

Thanks & Regards,

Shriraam

Re: Replacing the module name in a folder with another name via DXL scripting
KBSri - Fri Sep 20 04:35:29 EDT 2013

KBSri - Thu Sep 19 02:45:23 EDT 2013

Hello Louie,

I tried creating buffer using you sample function, but it is not working.

I am getting syntax error in line :  then return(in_Name[match 1] ToField in_Name[match 3])  //build new string

Here is my code:

string strFolder = "Test_FROP/First"

Folder delFold = folder(strFolder)
Module modHandle
Item deletedItem

for deletedItem in delFold do
{
    print "The Existing module Name in the current folder\n"
    print name(deletedItem)"\n"

    Regexp reFromField = regexp2("(.*)(_Shri_)(.*)")
    string ToField = "_Adv_"
    Buffer bufModName = create

    string ConvertName(string in_Name)
    {  
        // When the naame contains from field replace it with the to field
        // return null when there is no change
        bufModName = (deletedItem,in_Name)
        if (reFromField bufModName)
                then return(in_Name[match 1] ToField in_Name[match 3])  //build new string
        else return("")
    }  // end ConvertName()
}
Please guide me.

Thanks,

Shri

 

Hi Louie,

I am facing the problem in the function. Like do I need to initialize the Buffer here?

Or as per your sample function it does not have the buffer in it, but I have declared it.

Please guide me.

Thanks,

Shri

Re: Replacing the module name in a folder with another name via DXL scripting
MichaelGeorg - Fri Sep 20 08:28:54 EDT 2013

KBSri - Fri Sep 20 04:31:38 EDT 2013

Hi Louie,

I think actual rename is something which will work better.

I tried the belowcode in DXL to rename the module in a folder to be renamed.


string strFolder = "/Test_FROP/First"

Folder delFold = folder(strFolder)

Item deletedItem

string strModName = "FeatureRollout_Adv_Adapt"

for deletedItem in delFold do
{
    rename(delFold,strModName,"Adv")
}
print "Success\n"

But it is renaming the module at all. Please help me out.

Thanks & Regards,

Shriraam

Hello ShriaamB,

 

are you aware that "rename(delFold, strModName, "Adv") will rename the folder to strModName? Ist that really what you want?

Do you really want to rename deleted items? If you put some print statement in front of  the rename statement you can see that it is not possible to rename deleted items. So you will have to undelete the item first.

In total you will just need to call Louies ConvertName function in a loop over all items in the folder and then if the returned value isn't "" you need to use the rename statement.

 - Michael

Re: Replacing the module name in a folder with another name via DXL scripting
KBSri - Mon Sep 23 00:56:54 EDT 2013

MichaelGeorg - Fri Sep 20 08:28:54 EDT 2013

Hello ShriaamB,

 

are you aware that "rename(delFold, strModName, "Adv") will rename the folder to strModName? Ist that really what you want?

Do you really want to rename deleted items? If you put some print statement in front of  the rename statement you can see that it is not possible to rename deleted items. So you will have to undelete the item first.

In total you will just need to call Louies ConvertName function in a loop over all items in the folder and then if the returned value isn't "" you need to use the rename statement.

 - Michael

Thank Louie.

I modified the function declarations and function call. It worked really well.

Thanks,

Shri