file-extension

Javascript If statement used to check file extensions not working

独自空忆成欢 提交于 2019-11-26 21:59:32
问题 I have a form in which people can enter file paths. I want to make sure that the paths they are entering point to pictures so here is what I thought would work. function checkExt() { var extension= /* I know that the code to cut the extension off of the file is working correctly so for now let's just go with it ok */ if(extension!="jpg" || "gif" || "bmp" || "png" || "whatever else") alert("The file extension you have entered is not supported"); } But this does not work. I have tracked it down

How to get only images using scandir in PHP?

♀尐吖头ヾ 提交于 2019-11-26 20:16:40
Is there any way to get only images with extensions jpeg , png , gif etc while using $dir = '/tmp'; $files1 = scandir($dir); 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. Rajesh Kumar R The actual question was using scandir and the answers end up in glob. There is a huge difference in

How to filter git diff based on file extensions?

梦想与她 提交于 2019-11-26 18:52:00
问题 Is there an option to restrict git diff to a given set of file extensions? 回答1: Yes, if you ensure that git expands a glob rather than your shell then it will match at any level so something like this (quotes are important) should work fine. git diff -- '*.c' '*.h' 回答2: Either use your shell's globstar (which does a recursive search) 1 ,2 : shopt -s globstar git diff -- *.py **/*.py or use find: find -name '*.py' -print0 | xargs -0 git diff -- Both of these are special-names and whitespace

Checking file extension

不羁的心 提交于 2019-11-26 18:17:54
I'm working on a certain program and I need to have it do different things if the file in question is a flac file, or an mp3 file. Could I just use this? if m == *.mp3 .... elif m == *.flac .... I'm not sure whether it will work. EDIT: When I use that, it tells me invalid syntax. So what do I do? lafras 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')) (Thanks to Wilhem Murdoch for the list of args to endswith ) os.path

JPG vs. JPEG image formats

大憨熊 提交于 2019-11-26 17:54:17
问题 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 printer. LaTeX doesn't seem to distinguish, as I gave it a .jpeg with the extension changed to .jpg and the result seems to be the same as if it had been a .jpg right from the start. I have wondered what the difference between the two is. I have come

Changing file extension in Python

不想你离开。 提交于 2019-11-26 17:39:46
问题 Suppose from index.py with CGI, I have post file foo.fasta to display file. I want to change foo.fasta 's file extension to be foo.aln in display file. How can I do it? 回答1: os.path.splitext(), os.rename() for example: # renamee is the file getting renamed, pre is the part of file name before extension and ext is current extension pre, ext = os.path.splitext(renamee) os.rename(renamee, pre + new_extension) 回答2: import os thisFile = "mysequence.fasta" base = os.path.splitext(thisFile)[0] os

File extensions and MIME Types in .NET

女生的网名这么多〃 提交于 2019-11-26 15:13:20
问题 I want to get a MIME Content-Type from a given extension (preferably without accessing the physical file). I have seen some questions about this and the methods described to perform this can be resumed in: Use registry information. Use urlmon.dll's FindMimeFromData. Use IIS information. Roll your own MIME mapping function. Based on this table, for example. I've been using no.1 for some time but I realized that the information provided by the registry is not consistent and depends on the

How to change filetype association in the registry?

∥☆過路亽.° 提交于 2019-11-26 14:16:19
问题 first time posting in StackOverflow. :D I need my software to add a couple of things in the registry. My program will use Process.Start(@"blblabla.smc"); to launch a file, but the problem is that most likely the user will not have a program set as default application for the particular file extension. How can I add file associations to the WindowsRegistry? 回答1: In addition to the answers already provided, you can accomplish this by calling the command line programs "ASSOC" and "FTYPE". FTYPE

Where does Windows store its “Open With” settings?

泪湿孤枕 提交于 2019-11-26 13:49:54
问题 I'm trying to programmatically check file associations by the file extension (for example .jnlp files). I keep reading that HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPFile\Shell\Open\Command is the Registry key to check. However, if you change the association through Windows Explorer: Open With > Choose Program > (Always use the selected program) the change isn't at all reflected in this Registry key. Where else is this information stored? 回答1: Take a look in: HKEY_CURRENT_USER\Software

What is the difference between creating JSF pages with .jsp or .xhtml or .jsf extension

痴心易碎 提交于 2019-11-26 12:57:25
I saw some examples creating the JSF pages with .jsp extension, other examples creating them with .xhtml extension, and other examples choose .jsf . I just would like to know what the difference is between above extensions when working with JSF pages, and how to choose the appropriate extension? BalusC JSP is an old view technology and widely used in combination with JSF 1.x. Facelets (by some people overgeneralized as XHTML ) is the successor of JSP and introduced as default view technology of JSF 2.x at end of 2009. When you were seeing JSPs, you were perhaps reading outdated books,