filepath

Why use os.path.join over string concatenation?

牧云@^-^@ 提交于 2019-11-27 03:42:26
I'm not able to see the bigger picture here I think; but basically I have no idea why you would use os.path.join instead of just normal string concatenation? I have mainly used VBScript so I don't understand the point of this function. Portable Write filepath manipulations once and it works across many different platforms, for free. The delimiting character is abstracted away, making your job easier. Smart You no longer need to worry if that directory path had a trailing slash or not . os.path.join will add it if it needs to. Clear Using os.path.join makes it obvious to other people reading

What does \\\\?\\ mean when prepended to a file path

烈酒焚心 提交于 2019-11-27 03:30:15
I found a reference to a file in a log that had the following format: \\?\C:\Path\path\file.log I cannot find a reference to what the sequence of \?\ means. I believe the part between the backslashes refers to a hostname. For instance, on my Windows computer, the following works just fine: dir \\?\C:\ and also, just fine with same result: dir \\.\C:\ Questions: Is there a reference to what the question mark means in this particular path format? What might generate a file path in such a format? Ferenc Deak A long read, but worth reading if you are in this domain: http://msdn.microsoft.com/en-us

Full path with double backslash (C#)

为君一笑 提交于 2019-11-27 03:24:39
问题 Is it possible to get a full path with double backslash by using Path.GetFullPath ? Something like this: C:\\Users\\Mammamia\\Videos\\Documents\\CFD\\geo_msh\\cubeOp.txt instead of this: C:\Users\Mammamia\Videos\Documents\CFD\geo_msh\cubeOp.txt Or is there any other method? 回答1: Do you mean this? Path.GetFullPath(path).Replace(@"\", @"\\"); 回答2: C:\\Users\\Mammamia\\Videos\\Documents\\CFD\\geo_msh\\cubeOp.txt is not a valid path, so I'm not sure why you'd want it, but: Path.GetFullPath

Check whether a path is valid in Python without creating a file at the path's target

最后都变了- 提交于 2019-11-27 02:47:35
I have a path (including directory and file name). I need to test if the file-name is a valid, e.g. if the file-system will allow me to create a file with such a name. The file-name has some unicode characters in it. It's safe to assume the directory segment of the path is valid and accessible ( I was trying to make the question more gnerally applicable, and apparently I wen too far ). I very much do not want to have to escape anything unless I have to. I'd post some of the example characters I am dealing with, but apparently they get automatically removed by the stack-exchange system. Anyways

git checkout error: unable to create file

大憨熊 提交于 2019-11-27 02:37:36
问题 While cloning a git repository from Linux to a Windows system, I am getting the following error in checkout the phase: $ git clone gituser@serveraddr:/git/git_repo.git git_WA Cloning into 'git_WA'... gituser@serveraddr's password: remote: Counting objects: 500846, done. remote: Compressing objects: 100% (118676/118676), done. remote: Total 500846 (delta 307739), reused 483023 (delta 291136) Receiving objects: 100% (500846/500846), 907.54 MiB | 9.04 MiB/s, done. Resolving deltas: 100% (307739

How to get the path of app(without app.exe)?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:22:10
问题 I want to get the path of my app like: "\\ProgramFiles\\myApp", I try to use the following code: string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; But it returns a path which has "\\myapp.exe" at the end. I also tried: string path = System.IO.Directory.GetCurrentDirectory(); But it throws an “NotSupportedException”. Is there any way to get a path without .exe at the end? 回答1: path = System.IO.Path.GetDirectoryName( path ); 回答2: Application.StartupPath should

How to build a full path string (safely) from separate strings?

橙三吉。 提交于 2019-11-27 01:26:03
问题 Does C++ have any equivalent to python's function os.path.join ? Basically, I'm looking for something that combines two (or more) parts of a file path so that you don't have to worry about making sure the two parts fit together perfectly. If it's in Qt, that would be cool too. Basically I spent an hour debugging some code and at least part of it was because root + filename had to be root/ + filename , and I'm looking to avoid that in the future. 回答1: Check out QDir for that: QString path =

Get the (last part of) current directory name in C#

安稳与你 提交于 2019-11-27 01:25:56
问题 I need to get the last part of current directory, for example from /Users/smcho/filegen_from_directory/AIRPassthrough , I need to get AIRPassthrough . With python, I can get it with this code. import os.path path = "/Users/smcho/filegen_from_directory/AIRPassthrough" print os.path.split(path)[-1] Or print os.path.basename(path) How can I do the same thing with C#? ADDED With the help from the answerers, I found what I needed. using System.Linq; string fullPath = Path.GetFullPath(fullPath)

Directory.GetFiles: how to get only filename, not full path? [duplicate]

谁说胖子不能爱 提交于 2019-11-27 00:49:43
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to get only filenames within a directory using c#? Using C#, I want to get the list of files in a folder. My goal: ["file1.txt", "file2.txt"] So I wrote this: string[] files = Directory.GetFiles(dir); Unfortunately, I get this output: ["C:\\dir\\file1.txt", "C:\\dir\\file2.txt"] I could strip the unwanted "C:\dir\" part afterward, but is there a more elegant solution? 回答1: You can use System.IO.Path

Find a file with a certain extension in folder

坚强是说给别人听的谎言 提交于 2019-11-27 00:29:36
Given a folder path (like C:\Random Folder ), how can I find a file in it that holds a certain extension, like txt ? I assume I'll have to do a search for *.txt in the directory, but I'm not sure how I'm supposed to start this search in the first place. Look at the System.IO.Directory class and the static method GetFiles . It has an overload that accepts a path and a search pattern. Example: string[] files = System.IO.Directory.GetFiles(path, "*.txt"); You could use the Directory class Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories) It's quite easy, actually. You can use the