This question already has answers here:
Path functions for URL
(5 answers)
Closed 7 years ago.
I need to manipulate paths that are/a/b/c/xxx etc. But Path class is determined that separators must be \. So if I do
var dir = Path.GetDirectoryName("/a/b/c/xxx");
I get "\a\b\c"
I know I can write code to do it myself but I wonder if there is a knob for Path that I haven't found yet
The path functions will only work with paths that are appropriate with your operating system. I suggest you just use a string.Replace.
string.Replace("/", #"\")
Related
This question already has answers here:
get path for my .exe [duplicate]
(4 answers)
Closed 5 years ago.
So I'm trying to find a way of accesing the path of the folder to copy files but I can't find a way to do it
string folderpath = "C:\Users\Marc Vila\Downloads\Version 3.5\WindowsForm1\WindowsForm1/Resources";
I don't want to do that because as soon as I move it it gives me an error, anyone knows a more efficient way to do it?
Thanks and regards
Note: I've tried System.IO but it gives me a lot of trouble
You need to get the assembly's path and then build a relative path on top of that.
Take the code from this answer and then use that to combine the paths:
var folderPath = Path.Combine(AssemblyDirectory, "Resources");
This question already has answers here:
Why does Path.Combine not properly concatenate filenames that start with Path.DirectorySeparatorChar?
(16 answers)
Closed 5 years ago.
I have two parts of a ftp server path. Let's name the /one and /two.
The full path I want to achieve is /one/two.
When I use System.IO.Path.Combine("/one", "/two"); the output is "/two".
Why is that so? I expected it to be "/one/two" as you would normally with windows paths.
Is this by design, wrong usage by me or a bug in the .net class (unlikely)?
(How) can I use System.IO.Path functionality to produce "/one/two"?
If path2 contains an absolute path, this method returns path2.
This question already has answers here:
How do I find the parent directory of a path?
(4 answers)
Closed 6 years ago.
I would like to cut last slash and corresponding file or folder given path in string variable (called pathVar)
For example, if pathVar = "c:\temp\a\b\c"
I would like to assign to newPathVar = "c:\temp\a\b"
What is the easier and best way in c# to do that?
Thanks!
You can use Path.GetDirectoryName for that.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Path.Combine for Urls?
I have a root directory like http://localhost/
I have a file name call sample.jpg
when I use Path.Combine(root, file), I get something like http://localhost\sample.jpg, I am wondering if I can get http://localhost/sample.jpg.
Path.Combine is designed for file system paths, not URLs, so I don't think it will give you what you desire in this case. You can always do the Path.Combine, followed by a String.Replace("\", "/") to correct your URL.
This question already has answers here:
How to implement glob in C#
(4 answers)
Closed 6 years ago.
Given a path c:\someFolder\**\*.exe. How can I get a list of files using this directory path. I know that one could use Directory.GetFiles(directoryPath) but this only works when there are no wildcard characters in directoryPath.
See: How to implement glob in C#