filenames

How do I change the name of a file path correctly in Python?

主宰稳场 提交于 2019-12-12 02:12:41
问题 My code specFileName = input("Enter the file path of the program you would like to capslock: ") inFile = open(specFileName, 'r') ified = inFile.read().upper() outFile = open(specFileName + "UPPER", 'w') outFile.write(ified) outFile.close() print(inFile.read()) This is basically make to take in any file, capitalize everything, and put it into a new file called UPPER"filename". How do I add the "UPPER" bit into the variable without it being at the very end or very beginning? As it won't work

Copy a set of files into specific directories based on filename

拈花ヽ惹草 提交于 2019-12-11 23:54:16
问题 How can I copy series of files located in one folder into a specified folder based on the each file name in Windows? For example the files: ProviderA.pdf copied to folder-> \ProviderA\report\ ProviderB.pdf copied to folder-> \ProviderB\report\ ProviderC.pdf copied to folder-> \ProviderC\report\ I would like to traverse the list of files and from the file name (minus the extension) be able to copy each file to the folder specified by the file name. Thank you in advance! 回答1: dir /b *.pdf >foo

Hide filenames for product images

天大地大妈咪最大 提交于 2019-12-11 23:50:34
问题 Is there any way that I can hide the image filenames for all products on a website so that, even if someone chooses to view the page source or image properties, they can't? I need a way to hide the filenames because in some cases they contain information that i dont want to display to the public. 回答1: You can make a PHP script that takes an opaque image ID, finds the corresponding image, and writes it out to the response stream. Thus, the image URLs on the client would look like ../Image.php

To get the file name in string

谁都会走 提交于 2019-12-11 21:31:36
问题 I have stored JSON file in my project folder externally by the following code, System.IO.File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("JSON.json"), jSearializer.Serialize(modified_listofstrings)); but now in another method I want to read only name of that file, how I am suppose to do that, if I read the file in string, I get the content of the file but I just want the name of the file by which it is stored. Any help will be greatly appreciated. --- Edited question---

Strip whitspace and make lower case up to hyphen - filename

雨燕双飞 提交于 2019-12-11 20:57:34
问题 I have a lot of text files which I am renaming with a specific format. Below I am able to remove whitespaces and make lower case. However, it is not the desired outcome. How would I be able to format(take out spaces and make lower case) everything up the hyphen and then take only the first white space after the hyphen? find /temp/ -depth -name "* *" -type f -exec rename 's/ +\././; y/A-Z /a-z_/' {} + Input Result: Hello Video - KEEP.txt Output: hello_video_-_keep.txt Desired result: hello

Extract part of filename

China☆狼群 提交于 2019-12-11 19:58:13
问题 I have multiple filenames that look something like; com.test. app1 .deb com.heavy.test. app2 .deb com.maybe-test. app3 .deb com.crazy. app-4 .deb I would like to get the bolded strings only. so far, I've got this, name=$(echo $file | sed 's!\(*.\)\(.*\).deb!\2!') EDIT: I have other files in the same dir that would name something like; com.company. name _1.0.2_arm.deb Currently, my code looks like; for file in *.deb; do name=$(echo "$file" | sed 's/^.*\.\([^.][^.]*\)\.deb$/\1/') echo $name

PHP/regex : Script to create filenames with dashes instead of spaces

荒凉一梦 提交于 2019-12-11 18:50:06
问题 I want to amend a PHP script I'm using in wordPress (Auto Featured Image plugin). The problem is that this script creates filenames for thumbnails based on the URLs of the image. That sounds great until you get a filename with spaces and the thumbnail is something like this%20Thumbnail.jpg and when the browser goes to http://www.whatever.com/this%20Thumbnail.jpg it converts the %20 to a space and there is no filename on the server by that name (with spaces). To fix this, I think I need to

PHP scandir filenames with Turkish characters

最后都变了- 提交于 2019-12-11 18:07:51
问题 I am listing documents with PHP scandir. I have problem with some characters like ğ, ı, ş... So this is my code; $directory = "document"; $scanned_directory = array_diff(scandir($directory, 1), array('..', '.')); foreach ($scanned_directory as &$value) { echo utf8_encode($value); } Actually the filename is "şığx.jpg" but the output is "þýðx.jpg". utf8_encode did not solved this. Can you help me? Thank you. 回答1: utf8_encode will not help you here, as your filesystem is likely in different

R Combine multiple .csv files and retain source csv file name in an additional column

↘锁芯ラ 提交于 2019-12-11 17:34:54
问题 Using R, I'm compiling 2400 .csv files into a single csv file. Each csv file to be combined has 2 columns and 10 rows. My problem is to add the source csv file.csv as third column for source reference. For Example I want to combine "File1.csv" and "File2.csv" File1.csv: Column1 Column2 -6 -9.29E-08 -5.9 -8.71E-08 -5.8 -8.19E-08 -5.7 -7.72E-08 -5.6 -7.25E-08 -5.5 -6.81E-08 -5.4 -6.39E-08 -5.3 -6.01E-08 -5.2 -5.64E-08 -5.1 -5.29E-08 File2.csv : Column1 Column2 -5 -4.94E-08 -4.9 -4.63E-08 -4.8

unix move command regex

百般思念 提交于 2019-12-11 16:43:53
问题 I have a bunch of files in the format blahblah1.java.bak , blahblah2.java.bak , etc. And I want to change all the files ending with .bak to just .java . Is it possible to do this using the mv command? Perhaps something like mv (.*\.java)\.bak $1 ? 回答1: What's wrong with for i in *java.bak ; do mv "$i" `basename "$i" .bak` ; done or for i in *java.bak ; do mv "$i" "${i%.bak}" ; done if you are in bash. Command line file matching is not exactly the same as a regex in, say, Perl or =~ comparison