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) ?

  • @SpaceNoodle@lemmy.world
    link
    fedilink
    1
    edit-2
    8 months ago
    1. Set up WSL
    2. for file in * ; do mv “$file” $(basename “$file”) ; done

    Edit: the other commenter is right, I fucked up the usage of basename.

    • @FooBarrington@lemmy.world
      link
      fedilink
      38 months ago

      No, that doesn’t work, you have to pass the suffix you want to remove to basename:

      $ touch test.txt
      $ basename test.txt
      test.txt
      $ basename test.txt .txt
      test
      
      • föderal umdrehen
        link
        fedilink
        2
        edit-2
        8 months 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