Automator - Renaming it without any .html extension

If a folder/directory of the same base name of the file name does not exist at the same level as the file then it can be done, otherwise you cannot remove .html from the file name at the same level.

To remove the extension and the . you need to use:

  • Find: .html in fullname

If the fully qualified pathname contains .html in other then the actual file name, then you'll have to use a Run Shell Script action instead of the Rename Finder Items action.

  • Run Shell Script action:

    • Shell: /bin/bash
    • Pass input: as arguments

      for f in "$@"
      do
          [ ! -d "${f%.*}" ] || continue
          mv -n "$f" "${f%.*}"
      done
      

NOTE: As coded, if folder/directory of the same base name of the file name does exist at the same level as the file then nothing will happen and the file name will be unchanged.


If you need to clean up things, that is to remove trailing . in the file names from the previous renaming, do the following in Terminal:

cd /path/to/article
find . -type f -iregex '.*\.$' | for f in *; do [ ! -d "${f%.*}" ] || continue; mv -vn "$f" "${f%.*}"; done

Same note from above applies here as well.