表示当前目录,通常可省略。
string currentDirFile = "./data.txt"; // 等价于 "data.txt"
string parentDirFile = "../config.ini"; // 当前目录的父目录下的 config.ini
string grandparentDirFile = "../../log.txt"; // 当前目录的祖父目录下的 log.txt
假设当前目录是 C:\Projects\MyApp\bin\Debug:
string relativePath1 = "data.csv"; // C:\Projects\MyApp\bin\Debug\data.csv
string relativePath2 = "../config.xml"; // C:\Projects\MyApp\bin\config.xml
string relativePath3 = "../../src/AppSettings"; // C:\Projects\MyApp\src\AppSettings
| 符号 | 含义 | 示例 |
/ |
Unix 路径分隔符 |
/home/user/docs/file.txt |
\ |
Windows 路径分隔符 |
C:\Users\Public\file.txt |
./ |
当前目录(可省略) |
./data.txt 等价于 data.txt |
../ |
上级目录 |
../config.ini |
~ |
用户主目录(Unix/Linux) |
~/Documents |
\\ |
UNC 网络路径开头 |
\\server\share\folder |
file:/// |
文件 URI 前缀 |
file:///C:/Users/file.txt |