4

How can we rename all files in a folder having no extension at all to ".something". I have tried ren *.* *.jpeg and few more but nothing working

Rishabh
  • 41
  • 1
  • 1
  • 3
  • 1
    Possible duplicate of [Find and rename files with no extension?](https://stackoverflow.com/questions/1025410/find-and-rename-files-with-no-extension) – Rishav Feb 26 '18 at 18:56

7 Answers7

11

* matches any extension. You want to match no extension, so don't supply one: ren *. *.jpeg.

The above only works in cmd -- PowerShell's wildcards work differently, and mostly don't do anything special with extensions. What's more, batch renaming in PowerShell works differently. So:

dir -Filter "*." -File | ren -NewName { $_.name -replace "$", ".jpeg" }
Jeroen Mostert
  • 25,304
  • 2
  • 44
  • 78
  • 1
    This gave this error for me: ren : Cannot rename because item at '*.' does not exist. – EBGreen Feb 26 '18 at 14:38
  • @EBGreen: correct, that only works with cmd. The PowerShell version is more involved, see edit. (Although there may be a more elegant way.) – Jeroen Mostert Feb 26 '18 at 14:42
  • You explained very well , as earlier i was trying to run it through powershell.. by using simple cmd 'ren ......' command... & That's why it didn't worked.... Cool – Rishabh Feb 27 '18 at 19:37
3

"rename *. *.jpg" weirdly will bring up "The syntax of the command is incorrect." if there are no files without extensions in the location. I thought the command stopped working at first! So just letting people know if they have the same thing come up.

labrys
  • 89
  • 1
  • 7
2

You did everything correct but instead of *.* you ought to use *. as *.* searches for all files with all extensions but the former searches for all files with no extension and that is what you want. So here is your code:

rename *. *.something

You can refer to this answer for further help.

Rishav
  • 3,515
  • 29
  • 48
1

This is tested and works for me:

ls -file | ?{$_.extension -eq ''} | %{ren $_ ($_.name + '.jpeg')}
EBGreen
  • 35,429
  • 11
  • 62
  • 83
1

try this:

Get-ChildItem "c:\temp" -file "*." | rename-item -NewName {"{0}.something" -f $_.fullname}
Esperento57
  • 15,129
  • 3
  • 36
  • 41
0

For me as simple as ren * *.jpeg worked.

Alex
  • 721
  • 1
  • 6
  • 21
0

A slight variation:

dir -filter *. -file | rename-item -NewName {"$($_.name)`.jpg"}
Gene Laisne
  • 80
  • 1
  • 6