file-extension

How can I find all of the distinct file extensions in a folder hierarchy?

感情迁移 提交于 2019-11-26 12:49:14
问题 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? 回答1: Try this (not sure if it's the best way, but it works): find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u It work as following: Find all files from current folder Prints extension of files if any Make a unique sorted list 回答2: No need for the pipe to sort , awk can do it all: find . -type f

List of ALL MimeTypes on the Planet, mapped to File Extensions? [closed]

混江龙づ霸主 提交于 2019-11-26 12:03:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Is there a resource that lists ALL the mimeTypes in existence? I have found a few places with under 1000 mimeTypes, but then they still don\'t include common ones like .rar, .fla, .rb, .docx! Does anyone have a COMPLETE list of mimetypes? Not down to the most obsure \"company-only\" ones, but at least all of the

How to get file extension from string in C++

有些话、适合烂在心里 提交于 2019-11-26 12:03:05
问题 Given a string \"filename.conf\" , how to I verify the extension part? I need a cross platform solution. 回答1: You have to make sure you take care of file names with more then one dot. example: c:\.directoryname\file.name.with.too.many.dots.ext would not be handled correctly by strchr or find. My favorite would be the boost filesystem library that have an extension(path) function 回答2: Is this too simple of a solution? #include <iostream> #include <string> int main() { std::string fn =

Integrating into Windows Explorer context menu

耗尽温柔 提交于 2019-11-26 08:15:49
问题 I want to write a small tool, that does the following: When you right click on a file with a certain file-extension the Windows Explorer context menu shows an additional entry. When you click this entry a certain EXE is launched with this file as one of its parameters. I would like to use C#/.NET 2.0 for this. If it\'s not possible I could also do it with C++/Win32. My questions are: Is it possible with C# .NET 2.0? What are the necessary functions for integrating into the Windows Explorer

How to get only images using scandir in PHP?

試著忘記壹切 提交于 2019-11-26 07:33:04
问题 Is there any way to get only images with extensions jpeg , png , gif etc while using $dir = \'/tmp\'; $files1 = scandir($dir); 回答1: You can use glob $images = glob('/tmp/*.{jpeg,gif,png}', GLOB_BRACE); If you need this to be case-insensitive, you could use a DirectoryIterator in combination with a RegexIterator or pass the result of scandir to array_map and use a callback that filters any unwanted extensions. Whether you use strpos , fnmatch or pathinfo to get the extension is up to you. 回答2:

How can I check the extension of a file?

扶醉桌前 提交于 2019-11-26 05:16:13
问题 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 ... 回答1: Assuming m is a string, you can use endswith : if m.endswith('.mp3'): ... elif m.endswith('.flac'): ... To be case-insensitive, and to eliminate a potentially large else-if chain: m.lower().endswith(('.png', '.jpg', '.jpeg')) 回答2: os.path provides many functions for manipulating paths/filenames. (docs) os.path.splitext

Create registry entry to associate file extension with application in C++

你说的曾经没有我的故事 提交于 2019-11-26 02:08:20
问题 I would like to know the cleanest way of registering a file extension with my C++ application so that when a data file associated with my program is double clicked, the application is opened and the filename is passed as a parameter to the application. Currently, I do this through my wix installer, but there are some instances where the application will not be installed on ths user\'s computer, so I also need the option of creating the registry key through the application. Additionally, will

Extracting extension from filename in Python

主宰稳场 提交于 2019-11-25 23:45:19
问题 Is there a function to extract the extension from a filename? 回答1: Yes. Use os.path.splitext (see Python 2.X documentation or Python 3.X documentation): >>> import os >>> filename, file_extension = os.path.splitext('/path/to/somefile.ext') >>> filename '/path/to/somefile' >>> file_extension '.ext' Unlike most manual string-splitting attempts, os.path.splitext will correctly treat /a/b.c/d as having no extension instead of having extension .c/d , and it will treat .bashrc as having no

How can I get file extensions with JavaScript?

徘徊边缘 提交于 2019-11-25 23:29:01
问题 See code: var file1 = \"50.xsl\"; var file2 = \"30.doc\"; getFileExtension(file1); //returns xsl getFileExtension(file2); //returns doc function getFileExtension(filename) { /*TODO*/ } 回答1: Newer Edit: Lots of things have changed since this question was initially posted - there's a lot of really good information in wallacer's revised answer as well as VisioN's excellent breakdown Edit: Just because this is the accepted answer; wallacer's answer is indeed much better: return filename.split('.'

How to get the file extension in PHP? [duplicate]

烂漫一生 提交于 2019-11-25 23:20:59
Possible Duplicate: How to extract a 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 itself? ThiefMaster No need to use string functions. You can use something that's actually designed for what you want: pathinfo() : $path = $_FILES['image']['name']; $ext = pathinfo($path, PATHINFO_EXTENSION); Andrey This will work as well: $array = explode('.', $_FILES['image']['name']);