file-extension

Temporary file with specific file extension in Python 3

对着背影说爱祢 提交于 2019-12-03 23:58:53
问题 I am writing some unit tests for a piece of code that takes a path and attempts to load the file if it has a known extension, then does more careful checking. In the unit test, I would like to create a temporary file that has the correct extension, but incorrect contents, in my case an empty file posing as test.tif . How can I create a temporary file while specifying the extension (or the entire name), using the tempfile module? I have looked at the NamedTemporaryFile class, as well as the

Android Share custom file

前提是你 提交于 2019-12-03 22:19:46
问题 I created my own file extension ( .oli ). If the user clicks on a file with this extension my app starts and loads the included data. This works like expected. The problem is I would like to give the user of my app the opportunity to share a file (Example: filename.oli). I implemented this so far: public void shareFile(){ File file = getShareableFile(); //Creates a .oli-file Intent shareIntent = new Intent(Intent.ACTION_SEND); Uri uri = Uri.fromFile(file); shareIntent.setType("*/*"); //Maybe

Does FileInfo.Extension return the last *.* pattern, or something else?

让人想犯罪 __ 提交于 2019-12-03 22:12:07
I'm curious what exactly the behavior is on the following: FileInfo info = new FileInfo("C:/testfile.txt.gz"); string ext = info.Extension; Will this return ".txt.gz" or ".gz"? What is the behavior with even more extensions, such as ".txt.gz.zip" or something like that? EDIT: To be clear, I've already tested this. I would like an explanation of the property. It will return .gz, but the explanation from MSDN ( FileSystemInfo.Extension Property ) isn't clear why: " The Extension property returns the FileSystemInfo extension, including the period (.). For example, for a file c:\NewFile.txt, this

What are common file extensions for web programming languages?

孤者浪人 提交于 2019-12-03 18:46:02
问题 What file extensions are used most commonly by different languages? Please don't put source file names (like .java) but rather extensions that would be present in a URL for rendered pages. Here is my (alphabetized) list so far ASP Classic asp ASP.NET aspx axd asx asmx ashx CSS css Coldfusion cfm Erlang yaws Flash swf HTML html htm xhtml jhtml Java jsp jspx wss do action JavaScript js Perl pl PHP php php4 php3 phtml Python py Ruby rb rhtml SSI shtml XML xml rss svg Other (C, perl etc.) cgi dll

Does PHP have a function that returns the correct file extension given a valid content type?

大城市里の小女人 提交于 2019-12-03 12:59:39
问题 Does PHP have a function that returns a file extension given a content type? I'm looking for something that works like: <?php function getFileExtension($contentType) { if ($contentType === 'image/png') { return '.png'; } elseif ($contentType === 'image/jpg') { return '.jpg'; } elseif ($contentType === 'application/zip') { return '.zip'; } else { return FALSE; } } The goal is to use a library function that has all content types handled. Based on the pattern above, I guess I could roll my own

Change file extensions of multiple files in a directory with terminal/bash?

血红的双手。 提交于 2019-12-03 12:47:45
问题 I'm developing a simple launchdaemon that copies files from one directory to another. I've gotten the files to transfer over fine. I just want the files in the directory to be .mp3's instead of .dat's Some of the files look like this: 6546785.8786.dat 3678685.9834.dat 4658679.4375.dat I want them to look like this: 6546785.8786.mp3 3678685.9834.mp3 4658679.4375.mp3 This is what I have at the end of the bash script to rename the file extensions. cd $mp3_dir mv *.dat *.mp3 exit 0 Problem is the

SPLFileInfo: get filename without extension

ⅰ亾dé卋堺 提交于 2019-12-03 11:36:00
I'm accessing a number of files in the SPLFileInfo object. I see a way to get the path, filename, and even extension of the file. Is there a way to get the filename without extension? Here's the code I've been working with but I'm hoping to get something more elegant. Is there an out of the box solution? $file = new SplFileInfo("path/to/file.txt.zip"); echo 'basename: '.$file->getBasename(); echo PHP_EOL; echo 'filename: '.$file->getFilename(); echo PHP_EOL; echo 'extension: '.$file->getExtension(); echo PHP_EOL; echo 'basename w/o extension: '.$file->getBasename('.'.$file->getExtension()); >

How to git grep only a set of file extensions

天大地大妈咪最大 提交于 2019-12-03 10:48:31
How do you perform a git grep and limit the files checked to a set of files. I would like to be able to grep the contents of .cpp and .h files looking for MyFunc. eg: git grep "MyFunc" -- *.[hc]* However this also matches, .c files and .cs files. Use: git grep "MyFunc" -- '*.cpp' '*.h' The quotes are necessary so that git expands the wildcards rather than the shell. If you omit them, it'll only search files in the current directory, rather than including subdirectories. This can be achieved when using git bash in Windows by using: git grep "MyFunc" -- *.{cpp,h} or even simpler: git grep

Javascript - get extension from base64 image

懵懂的女人 提交于 2019-12-03 10:04:42
I have a base64 encoded image returned from a service and it looks like this: /9j/4AAQSkZJRgABAQEASABIAAD/4Yp2aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/Pgo8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA0LjEtYzAzNiA0Ni4yNzcwOTIsIEZyaSBGZWIgMjMgMjAwNyAxNDoxNjoxOCAgICAgICAgIj4KICAgPHJkZjpSREYgeG1.... etc How can i detect / check the image extension? For a String (which you can parse out of an image) you can do this: // Create Base64 Object var Base64={_keyStr:

Save file with appropriate extension in a Save File prompt

隐身守侯 提交于 2019-12-03 09:52:24
In my application I use a SaveFileDialog to pop up a Save As window. I have restricted in the file type section the file to be saved as .dat with the following code. sfdialog.Filter = "Data Files (*.dat*)|*.dat*"; What I want to know how to do is make it automatically save with the .dat extension. Currently it just saves with no extension unless I specifically save it as filename.dat. Francis B. SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Data Files (*.dat)|*.dat"; dlg.DefaultExt = "dat"; dlg.AddExtension = true; The AddExtension and DefaultExt properties. For example: sfdialog