If I have a string variable that has:
"C:\temp\temp2\foo\bar.txt"
and I want to get
"foo"
what is the best way to do this?
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).
Get the directory name with dirname() PHP's dirname() function returns just the directory part of the full path.
Paths include the root, the filename, or both. That is, paths can be formed by adding either the root, filename, or both, to a directory.
The FullName property returns just the full path of a file including the file name.
Use:
new FileInfo(@"C:\temp\temp2\foo\bar.txt").Directory.Name
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