filenames

How to get a batch file to handle spaces in file names?

China☆狼群 提交于 2019-12-01 01:26:46
问题 I am using the following batch file to make a zip file for each xml in a folder: FOR %%f in ("C:\files\*.xml") DO 7za.exe a C:\files\zips\%%~nf.zip (%%f) However if the file name has a space in it ( test plop.xml ) then the batch file does not work. It seems to split the name and thinks it is 2 files. How to modify the batch file so that it properly handles file names with spaces? 回答1: Try placing quotes around the output file name. Change FOR %%f in ("C:\files*.xml") DO 7za.exe a C:\files

PathCanonicalize equivalent in C#

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 00:34:59
问题 What is the equivalent to PathCanonicalize in C#? Use: I need to take a good guess whether two file paths refer to the same file (without disk access). My typical approach has been throwing it through a few filters like MakeAbsolute and PathCanonicalize, and then do a case-insensitive comparison. 回答1: quick and dirty: In the past I have created a FileInfo object from the path string and then used the FullName property. This removes all of the ..\'s and the .\'s. Of course you could interop:

How do I write a file whose *filename* contains utf8 characters in Perl?

泄露秘密 提交于 2019-12-01 00:14:17
问题 I am struggling creating a file that contains non-ascii characters. The following script works fine, if it is called with 0 as parameter but dies when called with 1 . The error message is open: Invalid argument at C:\temp\filename.pl line 15. The script is started within cmd.exe . I expect it to write a file whose name is either (depending on the paramter) äöü.txt or äöü☺.txt . But I fail to create the filename containing a smiley. use warnings; use strict; use Encode 'encode'; # Text is

Extract files with invalid characters in filename with Python

风流意气都作罢 提交于 2019-11-30 23:27:29
I use python's zipfile module to extract a .zip archive (Let's take this file at http://img.dafont.com/dl/?f=akvaleir for example.) f = zipfile.ZipFile('akvaleir.zip', 'r') for fileinfo in f.infolist(): print fileinfo.filename f.extract(fileinfo, '.') Its output: Akval�ir_Normal_v2007.ttf Akval�ir, La police - The Font - Fr - En.pdf Both files are unaccessable after extraction because there are invalid encoded characters in their filenames. The problem is zipfile module doesn't have an option to specify output filenames. However, "unzip akvaleir.zip" escapes the filename well: root@host:~#

Batch parameter %~s1 gives incorrect 8.3 short name

给你一囗甜甜゛ 提交于 2019-11-30 19:51:18
I'm trying to write a batch file in Windows XP that takes in a fully-qualified path name and outputs the 8.3 short name version... @echo off echo "%~s1" I have come across one particular case where this outputs an incorrect path and file... C:\>test.bat "C:\Documents and Settings\angus\Local Settings\Temporary Internet Files\Content.IE5\2JSTM34V\62[1].ja2" "C:\DOCUME~1\angus\LOCALS~1\TEMPOR~1\Content.IE5\2JSTM34V\62_1_~1.JA2M34V\62[1].ja2" Note that the above output ("C:\DOCUME~1\angus\LOCALS~1\TEMPOR~1\Content.IE5\2JSTM34V\62_1_~1.JA2M34V\62[1].ja2") does not exist. If I remove the ".JA2M34V

Create Unique Image Names

大憨熊 提交于 2019-11-30 17:43:37
问题 What's a good way to create a unique name for an image that my user is uploading? I don't want to have any duplicates so something like MD5($filename) isn't suitable. Any ideas? 回答1: as it was mentioned, i think that best way to create unique file name is to simply add time(). that would be like $image_name = time()."_".$image_name; 回答2: Grab the file extension from uploaded file: $ext = pathinfo($uploaded_filename, PATHINFO_EXTENSION); Grab the time to the second: time() Grab some randomness

For /f processing filename with spaces

我的梦境 提交于 2019-11-30 17:22:28
I want to do some processing on each line of a file. for /f "delims=" %%i in ("%RF_PROPERTIES%") do ( echo %%i ) My RF_PROPERTIES points to a file path with spaces (c:\program files\Arcot systems\conf\rf.properties). It is complaining saying Environment variable C:\Program Files\Arcot not defined, even though I have provided quotes. How to get it working? Try adding the usebackq option: for /f "usebackq delims=" %%i in ("%RF_PROPERTIES%") do ( echo %%i ) Explanation from the output of for /? : usebackq - specifies that the new semantics are in force, where a back quoted string is executed as a

C# - Easiest way to parse filename with spaces eg. “C:\Test\File with spaces.txt”

旧城冷巷雨未停 提交于 2019-11-30 16:57:19
问题 I am trying to pass a full file path to FFMPEG. C:\TestFolder\Input\Friends - Season 6 - Gag Reel.avi and it's obviously not liking the fact the path has spaces in it, erroring like so: C:\TestFolder\Input\Friends: no such file or directory So what's the easiest way to use filenames with spaces in them? Should I just replace all whitespaces with ~ characters or is there a better way? I have tried escaping the string with various characters: @"C:\TestFolder\Input\Friends - Season 6 - Gag Reel

How to rename files with a specific pattern in R?

流过昼夜 提交于 2019-11-30 14:51:37
There are some .fcs files in a data.000X format (where X = 1, 2, 3...) in a directory. I want to rename every n file to the following format: exp.fcs (where exp is a text from a vector) if the file to be renamed is an .fcs file. in other words : I want to rename files to exp.txt, where exp is a text and not a consecutive letter(s) i.e. F, cA, K, etc. For example, from: data.0001, data.0002, data.0003, data.0004, data.0005, data.0006... to textF_a.fcs, textF_b.fcs, textF_c.fcs, textVv_a.fcs, textVv_b.fcs, textVv_c.fcs ... I tried to do it with file.rename(from, to) but failed as the arguments

Android filename with white space cannot be opened

匆匆过客 提交于 2019-11-30 14:18:02
问题 My code works correctly while opening a file in sdcard. However, if I open a filename with white space then error occurs (example: Path - "/sdcard/download/hello hi.jpg"). I tried string.replace(" ","%20"); it doesn't work try { File file = new File(paths); if (file.exists()) { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(paths)); if (!mimeType.equals("")