filenames

Replacing Filename characters with python

给你一囗甜甜゛ 提交于 2019-12-04 09:31:12
问题 I have some code which adds the word "_manual" onto the end of a load of filenames.. I need to change the script so that it deletes the last two letters of the filename (ES) and then replaces it with _ES_Manual for example: AC-5400ES.txt --> AC-5400_ES_manual.txt How would i incorporate that function into this code? folder = r"C:/Documents and Settings/DuffA/Bureaublad/test" import os # glob is unnecessary for root, dirs, filenames in os.walk(folder): for filename in filenames: fullpath = os

Is this the best way to get unique version of filename w/ Python?

自作多情 提交于 2019-12-04 09:08:13
问题 Still 'diving in' to Python, and want to make sure I'm not overlooking something. I wrote a script that extracts files from several zip files, and saves the extracted files together in one directory. To prevent duplicate filenames from being over-written, I wrote this little function - and I'm just wondering if there is a better way to do this? Thanks! def unique_filename(file_name): counter = 1 file_name_parts = os.path.splitext(file_name) # returns ('/path/file', '.ext') while os.path

Overlaying an image's filename using ImageMagick (or similar)

删除回忆录丶 提交于 2019-12-04 09:08:03
问题 I know ImageMagick's annotate command can superimpose some text over an image, but can it use the image's filename as this text? I would've assumed so, but can't seem to find direct documentation that confirms this. No doubt some combination of parameters can manage this, or is there a better way of doing this in a script? 回答1: Eric L.'s answer is correct -- +1 from me for it! -- but -annotate doesn't give you much control over the appearance of the text. If you look for prettyness, then

Is there a cross-platform Java method to remove filename special chars?

落花浮王杯 提交于 2019-12-04 07:48:55
问题 I'm making a cross-platform application that renames files based on data retrieved online. I'd like to sanitize the Strings I took from a web API for the current platform. I know that different platforms have different file-name requirements, so I was wondering if there's a cross-platform way to do this? Edit: On Windows platforms you cannot have a question mark '?' in a file name, whereas in Linux, you can. The file names may contain such characters and I would like for the platforms that

Linux - Replacing spaces in the file names

梦想的初衷 提交于 2019-12-04 07:22:10
问题 I have a number of files in a folder, and I want to replace every space character in all file names with underscores. How can I achieve this? 回答1: This should do it: for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done 回答2: I prefer to use the command 'rename', which takes Perl-style regexes: rename "s/ /_/g" * You can do a dry run with the -n flag: rename -n "s/ /_/g" * 回答3: Use sh... for i in *' '*; do mv "$i" `echo $i | sed -e 's/ /_/g'`; done If you want to try this out before

File name? Path name? Base name? Naming standard for pieces of a path

谁说胖子不能爱 提交于 2019-12-04 07:17:36
问题 I keep getting myself in knots when I am manipulating paths and file names, because I don't have a common naming system that I use. I need to come up with a naming standard and stick to it, and I would like to be clear and consistent with others, so I am opening up to learn the canonical answers. Consider this toy problem: (Windows example, but hopefully answer should be platform independent) You have been given the full name of a folder: C:\users\OddThinking\Documents\My Source. You want to

VBA Excel file to CSV, keeps CSV filename same as original workbook

梦想的初衷 提交于 2019-12-04 06:34:20
问题 I am trying to find a fast way to save my xlsx files as csv files with the same file-name as the xlsx file (just in csv format). I have recorded a macro with shortcut, But the issue is that whenever I try with a new file it saves as a the same file-name I recorded initial macro with (i.e. see below, probably because I have the file labelled in code as: 3WDL_1 (2014-08-07)10secDataTable sit.csv ). Is there something I need to replace 3WDL_1 (2014-08-07)10secDataTable sit.csv with to make the

How to get pattern rules to match file names with spaces in Makefile?

巧了我就是萌 提交于 2019-12-04 06:30:34
In the GNU make docs, '%' is documented to match "any nonempty substring". However, it seems it actually only matches non-empty substrings that do not contain whitespace. For example, say you do this: mkdir /tmp/foo cd /tmp/foo echo 'int main() { return 0; }' > "test.c" echo 'int main() { return 0; }' > "test space.c" Now, you should be able to build these using GNU Make's built-in pattern rules: anthony@Zia:/tmp/foo$ make "test" cc test.c -o test anthony@Zia:/tmp/foo$ make "test space" make: *** No rule to make target `test space'. Stop. The same problem happens when you write a makefile.

Android get date and insert to filename

江枫思渺然 提交于 2019-12-04 06:20:28
I am having a quite annoying problem. I want to get the current date/time and insert it into a filename but I can't for my life get it to work. I want to get the time as 2011-11-18 12:13:57 and then insert it into my filename filename-2011-11-18-12:13:57.tar.gz I have tried SimpleDateFormat etc. but it just won't work! (I am writing in Eclipse Indigo) You can use this: SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US); Date now = new Date(); String fileName = formatter.format(now) + ".tar.gz"; Also you must be getting an error somewhere, that would help a lot

How to know character encoding of file names depending on the filesystem

耗尽温柔 提交于 2019-12-04 06:17:18
I would like to know the character encoding of the file names in a filesystem in order to display correctly them in a GUI. How should I do this ? I suppose I get different character encoding depending on the file system (FAT, NTFS, ext3, etc.) Thank you (I work in C++ but this topic is not language related) Eugene Mayevski 'Allied Bits NTFS is Unicode (UTF-16). exFAT is Unicode as well. Original FAT and fAT32 use OEM character set (read more on MSDN ). On Linux and Unix filename may contain any bytes except NUL and the charater set is not defined. Consequently each application decides itself