A suffix appended to the end of a filename, in order to identify the type of file. It is (typically) separated from the filename by a period symbol.
Questions tagged [file-extension]
1147 questions
1782
votes
33 answers
Extracting extension from filename in Python
Is there a function to extract the extension from a filename?

Alex
- 43,191
- 44
- 96
- 127
965
votes
18 answers
What file uses .md extension and how should I edit them?
On GitHub, several projects have README.md files. It seems like a simple format file to express text and pictures.
I guess there is an editor or syntax explanation somewhere.
Where can I find an introduction to .md files?

Lai Yu-Hsuan
- 27,509
- 28
- 97
- 164
854
votes
31 answers
How to get a file's extension in PHP?
This is a question you can read everywhere on the web with various answers:
$ext = end(explode('.', $filename));
$ext = substr(strrchr($filename, '.'), 1);
$ext = substr($filename, strrpos($filename, '.') + 1);
$ext =…

Bite code
- 578,959
- 113
- 301
- 329
717
votes
36 answers
How can I get file extensions with JavaScript?
See code:
var file1 = "50.xsl";
var file2 = "30.doc";
getFileExtension(file1); //returns xsl
getFileExtension(file2); //returns doc
function getFileExtension(filename) {
/*TODO*/
}

Sergio del Amo
- 76,835
- 68
- 152
- 179
513
votes
5 answers
How to get the file extension in PHP?
I wish to get the file extension of an image I am uploading, but I just get an array back.
$userfile_name = $_FILES['image']['name'];
$userfile_extn = explode(".", strtolower($_FILES['image']['name']));
Is there a way to just get the extension…

Keith Power
- 13,891
- 22
- 66
- 135
331
votes
18 answers
How can I find all of the distinct file extensions in a folder hierarchy?
On a Linux machine I would like to traverse a folder hierarchy and get a list of all of the distinct file extensions within it.
What would be the best way to achieve this from a shell?

GloryFish
- 13,078
- 16
- 53
- 43
305
votes
10 answers
Given a filesystem path, is there a shorter way to extract the filename without its extension?
I program in WPF C#. I have e.g. the following path:
C:\Program Files\hello.txt
and I want to extract hello from it.
The path is a string retrieved from a database. Currently I'm using the following code to split the path by '\' and then split…

KMC
- 19,548
- 58
- 164
- 253
291
votes
14 answers
How can I check the extension of a file?
I'm working on a certain program where I need to do different things depending on the extension of the file. Could I just use this?
if m == *.mp3
...
elif m == *.flac
...

wkoomson
- 3,077
- 2
- 15
- 10
288
votes
6 answers
JPG vs. JPEG image formats
I often use JPEG images, and I have noticed that there are two very similar file extensions: .jpg, which my mobile's camera and the Preview application use, and .jpeg, with which Image Capture saves the images from scanning with my Canon MX455…

MickG
- 3,216
- 2
- 14
- 22
266
votes
6 answers
What is phtml, and when should I use a .phtml extension rather than .php?
I'm wondering what the difference between .phtml and .php files is, and when to use one over the other.

fvgs
- 21,412
- 9
- 33
- 48
255
votes
11 answers
Should you use .htm or .html file extension? What is the difference, and which file is correct?
What is the difference between the .htm and .html file extension?
Why there are two of them?
Which is correct?

CannibalSmith
- 4,742
- 10
- 44
- 52
238
votes
10 answers
How to filter git diff based on file extensions?
Is there an option to restrict git diff to a given set of file extensions?

vfclists
- 19,193
- 21
- 73
- 92
233
votes
3 answers
Why do Objective-C files use the .m extension?
Since I started learning Objective-C and Cocoa, I've been wondering why they have chosen the extension .m for the implementation files - was it supposed to mean something, or was it just a random letter?

Kuba Suder
- 7,587
- 9
- 36
- 39
193
votes
14 answers
How to find the extension of a file in C#?
In my web application (asp.net,c#) I am uploading video file in a page but I want to upload only flv videos. How can I restrict when I upload other extension videos?

Surya sasidhar
- 29,607
- 57
- 139
- 219
133
votes
6 answers
recursively add file extension to all files
I have a few directories and sub-directories containing files with no file extension. I want to add .jpg to all the files contained within these directories. I've seen bash scripts for changing the file extension but not for just adding one. It also…

robjmills
- 18,438
- 15
- 77
- 121