FileExtension

FileExtension["file"]

gives the file extension for a file name.

Details and Options

  • FileExtension["name.ext"] gives "ext".
  • FileExtension gives the extension that appears after the last . in a file name.
  • If there are multiple endings to a file name, separated by ., FileExtension gives only the last one.
  • FileExtension gives "" if there is no file extension, if the file name has the form of a directory name, or ends with a . character.
  • FileExtension ignores any directory specification.
  • FileExtension by default assumes pathname separators and other conventions suitable for your operating system.
  • FileExtension[,OperatingSystem->"os"] uses the conventions of the specified operating system. Possible choices are "Windows", "MacOSX", and "Unix".
  • FileExtension just operates on names of files; it does not actually search for the file specified.
  • FileExtension[File["file"]] is also supported.

Examples

open allclose all

Basic Examples  (1)

Find the file extension of a string:

Scope  (1)

Find the extension of the file specified by the File object:

Possible Issues  (1)

The period is not part of the file extension:

Or the file base name:

Wolfram Research (2008), FileExtension, Wolfram Language function, https://reference.wolfram.com/language/ref/FileExtension.html (updated 2016).

Text

Wolfram Research (2008), FileExtension, Wolfram Language function, https://reference.wolfram.com/language/ref/FileExtension.html (updated 2016).

CMS

Wolfram Language. 2008. "FileExtension." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/FileExtension.html.

APA

Wolfram Language. (2008). FileExtension. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FileExtension.html

BibTeX

@misc{reference.wolfram_2024_fileextension, author="Wolfram Research", title="{FileExtension}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/FileExtension.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_fileextension, organization={Wolfram Research}, title={FileExtension}, year={2016}, url={https://reference.wolfram.com/language/ref/FileExtension.html}, note=[Accessed: 22-November-2024 ]}