-2

I am trying to rename some configuration files that reside into a folder. Some of them have the ".disabled" extentions, some don't.

My intention: foreach file in files-to-change.txt (relative path to the .config file, one under the other), if the file has the ".disabled" extension, remove it, if it doesn't have it, add it. This needs to apply only to the files in the .txt source file.

Basically the files

app_config\file1.config
app_config\CBS\file2.config.disabled
app_config\file3.config
app_config\CBD\Testing\file4.config.disabled

reside in the txt file and they need to match with the files in the destination folder in which I need to change the extension.

I miss the login in creating a proper script to have this completed.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Alex
  • 75
  • 7

1 Answers1

0

where it says -path you will need to change this to reflect the location of your files. You can use rename-item cmdlet, here is a simple script i created :

$name=(Get-ChildItem -Path 'C:\testing\New folder\').FullName
foreach ($item in $name) {
 if ($item.Contains("disabled")) 
   {
   rename-item -Path $item -NewName $item.Replace(".disabled","") -ErrorAction SilentlyContinue
   }
else 
   {
   rename-item -path $item -newname $item.Replace(".config.",".config.disabled.") -ErrorAction SilentlyContinue
   }
}
ok1
  • 1
  • 5