0

Is it possible to batch rename a series of files and keep the original extensions in a sequence?

For example, if you had the files in a directory:

dogfile1.jpg, wolffile493.png, and dogfile59.jpg

and wanted to rename them dog1.jpg, dog2.png, dog3.jpg

I saw you can use this to batch rename but it renames it to the extension you select (ex. jpg):

$nr=1 
Dir | %{Rename-Item $_ -NewName (‘NewFile{0}.jpg’ -f $nr++)}

1 Answer 1

1

Here you go:

PS C:\tmp\y> $nr=1; Dir | %{Rename-Item $_ -NewName (‘NewFile{0}{1}’ -f $nr++, $_.extension)}

Here's a quick demonstration:

PS C:\tmp\y> echo "123" > firstfile.txt
PS C:\tmp\y> echo "abc" > secondfile.jpg
PS C:\tmp\y> dir -Name
firstfile.txt
secondfile.jpg
PS C:\tmp\y> $nr=1; Dir | %{Rename-Item $_ -NewName (‘NewFile{0}{1}’ -f $nr++, $_.extension)}
PS C:\tmp\y> dir -Name
NewFile1.txt
NewFile2.jpg
PS C:\tmp\y> type *
123
abc
PS C:\tmp\y>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .