Rename multiple files in a folder, add a prefix (Windows)

前端 未结 8 978
迷失自我
迷失自我 2021-01-29 18:28

I\'d like to batch rename files in a folder, prefixing the folder\'s name into the new names. i.e. files in C:\\house chores\\ will all be renamed house chore

8条回答
  •  执念已碎
    2021-01-29 19:12

    The problem with the two Powershell answers here is that the prefix can end up being duplicated since the script will potentially run over the file both before and after it has been renamed, depending on the directory being resorted as the renaming process runs. To get around this, simply use the -Exclude option:

    Get-ChildItem -Exclude "house chores-*" | rename-item -NewName { "house chores-" + $_.Name }
    

    This will prevent the process from renaming any one file more than once.

提交回复
热议问题