- 論壇徽章:
- 0
|
本帖最后由 ccporxy 于 2011-08-09 10:22 編輯
源碼跟進去發(fā)現 listdir 實際上是調用了win32 函數 FindFirstFile FindNextFile
來枚舉目錄信息。只不過會擴展一下傳入的路徑信息。
- if (wch != L'/' && wch != L'\\' && wch != L':')
- wnamebuf[len++] = L'\\';
- wcscpy(wnamebuf + len, L"*.*");
復制代碼 當傳入參數為'c 系統(tǒng)所在分區(qū)),會擴展為'c:*.*',如果此時分區(qū)為系統(tǒng)分區(qū)的話(并且當前進程
所在目錄也在同一個分區(qū)上),實際上查找的目錄是當前進程所在目錄。
其余情況<drive>: 等同于 <drive>:/ 等同于 <drive>:/*.* <drive>:/*
至于原因查看了msdn文檔,沒有收獲。
還是請大神來解釋吧。
查詢了下關于path的描述:
Relative Paths
For functions that manipulate files, the file names can be relative to the current directory. A file name is relative to the current directory if it does not begin with one of the following:
A drive name, which is either a drive letter followed by a colon, or a UNC name.
A directory name separator (backslash), for example, \subdirectory).
If the file name begins with a disk designator and a backslash, it is a full path (for example, C:\tmp). If a file name begins with only a disk designator, it is a relative path to the current directory on the drive with the specified letter (for example, C:tmp.txt refers to a file in the current directory on drive C).
原因就在此了~ |
|