filenames

File name has two backslashes C#

我们两清 提交于 2019-12-02 01:43:32
There is probably an easy answer for this, but when I added DateTime.Now.ToString() to my fileName it adds an extra \ for every \ I have so C:\Temp becomes C:\\Temp which causes the file not to save. This is the code in question String fileName = @"C:\Temp\data_" + DateTime.Now.ToString() + ".txt"; For example the output could be C:\\Temp\\data_12/04/2012 20:08:40.txt It should be C:\Temp\data_12/04/2012 20:08:40.txt Nope, that string really has single backslashes in. Print it out to the console and you'll see that. If you look at it in the debugger , you'll see the backslashes escaped - but

Pure ASP upload with utf-8 filenames

巧了我就是萌 提交于 2019-12-02 01:00:59
I'm have made a upload page in classic asp and it works fine, as long as the filenames are not in utf-8 characters. I have added charset til the page and the form accepts utf-8 characters but my files are saved as Доклад Региона.pdf bug should be Доклад Региона.pdf I don't know if there is anything more I can do or it is the "Pure-ASP file upload" that does not support utf-8 characters. Does anyone how to fix it? My asp page looks like this <% Response.CodePage = 65001 Response.CharSet = "utf-8" 'Create upload form 'Using Huge-ASP file upload 'Dim Form: Set Form = Server

tkinter - retrieve file name during askopenfile

点点圈 提交于 2019-12-02 00:59:09
I have a text editor made with Python and tkinter. This is my 'open file' method: def onOpen(self): file = askopenfile(filetypes=[("Text files", "*.txt")]) txt = file.read() self.text.delete("1.0", END) root.title(file) self.text.insert(1.0, txt) file.close() I would like to set the window title equal to the file name. At the moment I'm using whatever askopenfile return as the file name, but this returns for example: <_io.TextIOWrapper name='/Users/user/Desktop/file.txt' mode='r' encoding='UTF-8'> This, of course, isn't very nice. I would like whatever askopenfilename would return. But if I

Batch remove substring from filename with special characters in BASH

本小妞迷上赌 提交于 2019-12-02 00:53:19
问题 I have a list of files in my directory: opencv_calib3d.so2410.so opencv_contrib.so2410.so opencv_core.so2410.so opencv_features2d.so2410.so opencv_flann.so2410.so opencv_highgui.so2410.so opencv_imgproc.so2410.so opencv_legacy.so2410.so opencv_ml.so2410.so opencv_objdetect.so2410.so opencv_ocl.so2410.so opencv_photo.so2410.so They're the product of a series of mistakes made with batch renames, and now I can't figure out how to remove the middle ".so" from each of them. For example: opencv_ocl

Add index to filename for existing file (file.txt => file_1.txt)

随声附和 提交于 2019-12-02 00:14:17
I want to add an index to a filename if the file already exists, so that I don't overwrite it. Like if I have a file myfile.txt and same time myfile.txt exists in destination folder - I need to copy my file with name myfile_1.txt And same time if I have a file myfile.txt , but destintation folder contains myfile.txt and myfile_1.txt - generated filename has to be myfile_2.txt So the functionality is very similar to the creation of folders in Microsoft operating systems. What's the best approach to do that? Untested Code: File f = new File(filename); String extension = ""; int g = 0; int i = f

Process.Start filename using %temp%

为君一笑 提交于 2019-12-01 23:28:36
For some odd reaseon this code fails: p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi"; and this code succes: p.StartInfo.FileName = @"C:\Users\USERNAME\AppData\Local\Temp\SSCERuntime_x86-ENU.msi"; Is there any reason I am missing? Note I just copied the path, I don't think the rest of the code is needed but I'll put it anyway: Process p = new Process(); p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi"; p.StartInfo.Arguments = "/passive"; p.Start(); The Process class does not expand strings with environment variables (i.e. %temp% ). If you want to use environment variables to

Reading filename in multiple OS without encoding problem with Ruby

核能气质少年 提交于 2019-12-01 23:26:11
I want to get all filenames in UTF-8. For example, after I read filename in Windows, I do filename = Iconv.iconv("UTF-8", "Windows-1251", filename) In Ubuntu I don't convert filename and get it in UTF-8. Maybe exists some method to determine OS filename encoding? I do this on Ruby 1.9 when I want to make sure things are in UTF-8: if filename.encoding.to_s != 'UTF-8' filename.encode!('UTF-8') end Unless your OS gives a file name encoded with a coding system which doesn't support some special characters found on the file name, it can be encoded to UTF-8 without a hickup. 来源: https:/

How do I get the current script or class name in Scala?

老子叫甜甜 提交于 2019-12-01 23:20:31
问题 I'd like my Scala program to be able to programmatically determine either its script filename or its class name, store the string in a variable program and print out the name. Java has several methods for this. 回答1: I think this is the simplest: val program = new Exception().getStackTrace.head.getFileName 回答2: Parsing the stack trace as hinted by 0__ should take care of most of the use cases, in particular when the object with the main method is not in a file of the same name: package utils

Rename files during upload within Wordpress

谁说胖子不能爱 提交于 2019-12-01 22:41:58
问题 I am trying to rename upload filenames match the Post Title. This other thread shows how to rename to hash: Rename files during upload within Wordpress backend Using this code: function make_filename_hash($filename) { $info = pathinfo($filename); $ext = empty($info['extension']) ? '' : '.' . $info['extension']; $name = basename($filename, $ext); return md5($name) . $ext; } add_filter('sanitize_file_name', 'make_filename_hash', 10); Does anyone know the code to rename the file to match Post

Get parameters of .js file

孤者浪人 提交于 2019-12-01 20:57:31
I have a javascript file that I reference in HTML with standard <script src="foo.js?param"></script> . In the file I want to distinguish e.g. loading the file with foo.js from foo.js?auto and foo.js?noauto=true , but not if the file is renamed to bar.js and referenced with the same parameter. How can I accomplish this, preferably not using any framework? Take a look a scriptaculous' approach: var js = /scriptaculous\.js(\?.*)?$/; $$('head script[src]').findAll(function(s) { return s.src.match(js); }).each(function(s) { var path = s.src.replace(js, ''), includes = s.src.match(/\?.*load=([a-z,]*