6

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.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Rishabh
  • 61
  • 1
  • 1
  • 3
  • 2
    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

17

Asterisk * matches any extension. You want to match no extension, so don't supply one. Both of the below variants will do in your case:

  • ren * *.jpeg
  • ren *. *.jpeg

NOTE: you may read here about the peculiarities of using * and *. with the ren command.


The above only works in Windows Command shell (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" }
informatik01
  • 16,038
  • 10
  • 74
  • 104
Jeroen Mostert
  • 27,176
  • 2
  • 52
  • 85
  • 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
4

"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
  • 129
  • 1
  • 7
2

This is tested and works for me:

ls -file | ?{$_.extension -eq ''} | %{ren $_ ($_.name + '.jpeg')}
EBGreen
  • 36,735
  • 12
  • 65
  • 85
2

A slight variation:

dir -filter *. -file | rename-item -NewName {"$($_.name)`.jpg"}
Gene Laisne
  • 120
  • 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,818
  • 1
  • 31
  • 49
2

try this:

Get-ChildItem "c:\temp" -file "*." | rename-item -NewName {"{0}.something" -f $_.fullname}
Esperento57
  • 16,521
  • 3
  • 39
  • 45
0

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

Alex
  • 731
  • 1
  • 6
  • 21