Вопрос

I need to rename various files in different folders. There is a prefix 'f_' in all the filenames that need to be removed.
I managed to do this using the following lines in Powershell.

cd "C:\Users\pieter\Desktop\Folder1\Folder2\20140402_Export"
Get -ChildItem -filter "*f_*" -recurse | Rename-item -newname { $_.name -replace "f_","" }

This works, but how do I make a .bat out of this? I would like to doubleclick a script file that automatically does the same job.

Thanks!

Это было полезно?

Решение

Create a batch file and the following there, it will execute your command in Powershell thread and exit.

@powershell "cd 'C:\Users\pieter\Desktop\Folder1\Folder2\20140402_Export'; Get-ChildItem -filter "*f_" -recurse | Rename-item -newname { $_.name -replace 'f_','' }"

Другие советы

try this:

@cd /d "C:\Users\pieter\Desktop\Folder1\Folder2\20140402_Export"
for /f "delims=" %%a in ('dir /b /a-d /s "*f_*"') do (
   set "name=%%~na"
   setlocal enabledelayedexpansion
      set "new=!name:f_=!"
      ren "%%a" "!new!%%~xa"
   endlocal
)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top