How to rename multiple *file extensions* to *nil/no file extension* at once in Windows? - eviltoast

In case of renaming multiple file extensions to another, they suggested to type this command in cmd promt or powershell: ren *.(current extension name) *.(new extension name)

But what about to renaming multiple file extensions to nil or no file extension? How to replace this command *.(new extension name) ?

    • federalreverse-old@feddit.de
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      1 year ago

      That’s a bit dangerous for a few reasons:

      1. cat is the wrong command, because it outputs the file’s content, not the file’s name.
      2. my.awesome.file.txt would become an empty string, leading to errors. (The regex is not anchored to the end of the string ($), the . is not escaped, so it becomes a wild card, …)
      3. My awesome file.txt would trip up the loop and lead to unwanted results.

      I’d suggest this:

      for file in * ; do mv$file” $(echo$file” | sed -r 's/(\.tar)?\.[^.]*$//') ; done