Paths
The following illustrates how .NET evaluates different file paths.
| API Call | Result |
|---|---|
| Path.ChangeExtension("C:\windows\test.txt", ".dat") | C:\windows\test.dat |
| Path.ChangeExtension("C:\windows\test.txt", "dat") | C:\windows\test.dat |
| Path.ChangeExtension("/etc/passwd", ".txt") | /etc/passwd.txt |
| Path.ChangeExtension("/etc/passwd", "txt") | /etc/passwd.txt |
| Path.ChangeExtension("/etc/passwd/", "txt") | /etc/passwd/.txt |
| Path.Combine("C:\test\", "file.txt") | C:\test\/file.txt |
| Path.Combine("C:\test", "file.txt") | C:\test/file.txt |
| Path.Combine("C:\test", "C:\file.txt") | C:\test/C:\file.txt |
| Path.Combine("/etc", "passwd") | /etc/passwd |
| Path.Combine("etc", "passwd") | etc/passwd |
| Path.Combine("/etc", "/usr") | /usr |
| Path.GetDirectoryName("/etc/passwd") | /etc |
| Path.GetDirectoryName("/etc/passwd/") | /etc/passwd |
| Path.GetDirectoryName("C:\windows\system32") | |
| Path.GetDirectoryName("C:\windows\system32\") | |
| Path.GetExtension("/etc/passwd") | |
| Path.GetExtension("/etc/passwd/") | |
| Path.GetExtension("/etc/passwd/.txt") | .txt |
| Path.GetExtension("C:\windows\test.txt") | .txt |
| Path.GetFileName("/etc/passwd") | passwd |
| Path.GetFileName("/etc/passwd/") | |
| Path.GetFileName("/etc/passwd/.txt") | .txt |
| Path.GetFileName("C:\windows\test.txt") | C:\windows\test.txt |
| Path.GetFileNameWithoutExtension("/etc/passwd") | passwd |
| Path.GetFileNameWithoutExtension("/etc/passwd/") | |
| Path.GetFileNameWithoutExtension("/etc/passwd/.txt") | |
| Path.GetFileNameWithoutExtension("C:\windows\test.txt") | C:\windows\test |
| Path.GetFileNameWithoutExtension("C:\windows\test.txt.pgp") | C:\windows\test.txt |
| Path.GetFullPath("/etc/passwd") | /etc/passwd |
| Path.GetFullPath("/etc/passwd/") | /etc/passwd/ |
| Path.GetFullPath("/etc/passwd/.txt") | /etc/passwd/.txt |
| Path.GetFullPath("etc/passwd") | /maw-www/etc/passwd |
| Path.GetFullPath("C:\windows\test.txt") | /maw-www/C:\windows\test.txt |
| Path.GetInvalidFileNameChars() | ,/ |
| Path.GetInvalidPathChars() | |
| Path.GetPathRoot("/etc/passwd") | / |
| Path.GetPathRoot("/etc/passwd/") | / |
| Path.GetPathRoot("/etc/passwd/.txt") | / |
| Path.GetPathRoot("etc/passwd") | |
| Path.GetPathRoot("C:\windows\test.txt") | |
| Path.GetRandomFileName() | 04nrplxs.d5m |
| Path.GetTempFileName() | /tmp/tmpEUekXe.tmp |
| Path.GetTempPath() | /tmp/ |
| Path.HasExtension("/etc/passwd") | False |
| Path.HasExtension("/etc/passwd/") | False |
| Path.HasExtension("/etc/passwd/.txt") | True |
| Path.HasExtension("etc/passwd") | False |
| Path.HasExtension("C:\windows\test.txt") | True |
| Path.IsPathRooted("/etc/passwd") | True |
| Path.IsPathRooted("/etc/skel/") | True |
| Path.IsPathRooted("C:\windows\system32") | False |
| Path.IsPathRooted("C:\windows\system32\") | False |
| Path.IsPathRooted("etc/passwd") | False |
| Path.IsPathRooted("windows\system32\") | False |