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

前端 未结 8 958
迷失自我
迷失自我 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:22

    Free Software 'Bulk Rename Utility' also works well (and is powerful for advanced tasks also). Download and installation takes a minute.

    See screenshots and tutorial on original website.

    --

    I cannot provide step-by-step screenshots as the images will have to be released under Creative Commons License, and I do not own the screenshots of the software.

    Disclaimer: I am not associated with the said software/company in any way. I liked the product for my own task, it serves OP's and similar requirements, thus recommending.

    0 讨论(0)
  • 2021-01-29 19:23

    I know it's an old question but I learned alot from the various answers but came up with my own solution as a function. This should dynamically add the parent folder as a prefix to all files that matches a certain pattern but only if it does not have that prefix already.

    function Add-DirectoryPrefix($pattern) {
        # To debug, replace the Rename-Item with Select-Object
        Get-ChildItem -Path .\* -Filter $pattern -Recurse | 
            Where-Object {$_.Name -notlike ($_.Directory.Name + '*')} | 
            Rename-Item -NewName {$_.Directory.Name + '-' + $_.Name}
            # Select-Object -Property Directory,Name,@{Name = 'NewName'; Expression= {$_.Directory.Name + '-' + $_.Name}}
    }
    

    https://gist.github.com/kmpm/4f94e46e569ae0a4e688581231fa9e00

    0 讨论(0)
提交回复
热议问题