This question already has answers here:
How can one get an absolute or normalized file path in .NET?
(4 answers)
Closed 9 years ago.
How to get canonical file name by non-canonical one.
E.g. I want to call function which converts "C:\Program files\..\Windows\aaa.txt" to "C:\Windows\aaa.txt"
I am looking for something like Java File.getCanonicalPath()
You can use the Path.GetFullPath method for this.
Example:
Console.WriteLine(Path.GetFullPath(#"C:\Program files\..\Windows\aaa.txt"));
Output:
C:\Windows\aaa.txt
System.IO.Path.GetFullPath("C:/Program files/../Windows/aaa.txt")
will return
"C:\\Windows\\aaa.txt"
Here is my suggestion:
string path = Path.GetFullPath(#"C:\Program files\..\Windows\aaa.txt");
Related
This question already has answers here:
How to write Unicode characters to the console?
(5 answers)
Closed 4 years ago.
i want to ask if is possible to add in a string the "⚠" character and make it executable in console with Console.WriteLine().
you can use this code;
System.Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.WriteLine("⚠");
This question already has answers here:
How to use Directory.GetFiles to get only gif types (or any other type)?
(2 answers)
Closed 6 years ago.
is it possible to get the names of .resx files? In runtime. I need to capture those names to get the available languages and load them into a combobox.
I have a folder
ProjectName
Multilanguage
Language.resx
Language.en-US.resx
Language.fr-FR.resx
I need in an array the names Language.resx, Language.en-US.resx and Language.fr-FR.resx
Thx!
You can use the GetFiles method on the Directory class to get all files recursively. It even supports a pattern:
string[] result = System.IO.Directory.GetFiles(#"C:\source\project",
"*.resx", System.IO.SearchOption.AllDirectories);
This question already has answers here:
C# - How to extract the file name and extension from a path?
(4 answers)
Closed 8 years ago.
Is it possible to separate the name of the file to it's file type/ file extension.
For example I have this file named sample.text. I want to get separate sample and .txt using c#.
Can anyone help me. Thanks.
You can use Path.GetExtension:
var extension =
Path.GetExtension("C:\\sample.txt"); // returns txt
..and Path.GetFileNameWithoutExtension:
var fileNameWithoutExtension =
Path.GetFileNameWithoutExtension("C:\\sample.txt"); // returns sample
This question already has answers here:
How can I compare (directory) paths in C#?
(14 answers)
Closed 8 years ago.
I need to check whether two relative file paths are equal or not.
String path1 = "a/b/c/file.txt";
String path2 = "/A/B/../B/C/file.txt";
Actually those two paths point to the same file. But how can I check this?
PS: Doing this for absolute paths works fine, with the approach described here.
You can use Path.GetFullPath (MSDN) to compare the absolute paths of your files.
This question already exists:
Closed 12 years ago.
Possible Duplicate:
String vs string in C#
What is the big difference between these datatypes? and were should I use it?
Short answer, there is no difference. They are just alias of each other, see
http://msdn.microsoft.com/en-us/library/ya5y69ds(VS.80).aspx for a complete list.
Have a look at: String vs string in C#