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
    arrow-up
    0
    ·
    edit-2
    1 year 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.

      • federalreverse-old@feddit.de
        link
        fedilink
        arrow-up
        0
        ·
        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