I have a folder in C:\Name\Folder\
and in that I have several files.
I need to display the full file path of the files in that folder.
It should display all the files in the format of C:\Name\Folder\file.txt
. My code is as follows;
string[] filePaths = Directory.GetFiles(@"C:\Name\Folder\");
for (int i = 0; i < filePaths.Length; ++i) {
string path = filePaths[i];
Console.WriteLine(System.IO.Path.GetFileName(path));
}
It only prints the file name, but I also need it to print the full path of the file.
The best Linux command to get file path is using pwd command. To use this command, type “pwd” into your terminal and press enter. This command will print the current working directory. The output will be the file path.
An absolute path refers to the complete details needed to locate a file or folder, starting from the root element and ending with the other subdirectories. Absolute paths are used in websites and operating systems for locating files and folders. An absolute path is also known as an absolute pathname or full path.
Whats wrong with simply printing path
variable?
Btw you can iterate files via foreach
statement:
foreach(var path in Directory.GetFiles(@"C:\Name\Folder\"))
{
Console.WriteLine(path); // full path
Console.WriteLine(System.IO.Path.GetFileName(path)); // file name
}
Use the following,
System.IO.Path.GetFullPath(path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With