How can I bulk rename files in PowerShell?

前端 未结 8 2058
春和景丽
春和景丽 2021-01-30 10:36

I\'m trying to do the following:

Rename-Item c:\\misc\\*.xml *.tmp

I basically want to change the extension on every files within a directory t

8条回答
  •  滥情空心
    2021-01-30 10:58

    This seems to work and is a pythonic i.e simple is better than complex (https://www.python.org/dev/peps/pep-0020/) way of doing it (once you are in the directory):

    $files = Get-ChildItem -file -Filter *.xml;
      ForEach ($file in $files)
      {
      $n = $file.Basename
      Copy-Item -Path $file -Destination "$n.tmp"
      Remove-Item "$n.xml"
      }
    

提交回复
热议问题