亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 11847 | 回復: 11
打印 上一主題 下一主題

奇怪的os.listdir結果 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-08-06 20:33 |只看該作者 |倒序瀏覽
win XP環(huán)境,用python 2.7自帶的IDLE,
當輸入os.listdir("c:")時,結果是python安裝目錄
但是os.listdir("d:")卻能得到d盤下的目錄,os.listdir("c:\")也能得到c盤下的目錄

大家有遇到這樣的問題嗎?

論壇徽章:
0
2 [報告]
發(fā)表于 2011-08-07 00:29 |只看該作者
回復 1# linux_arm

你試過 dir c: 和dir c:\ 有什么不同么?

論壇徽章:
0
3 [報告]
發(fā)表于 2011-08-07 10:50 |只看該作者
本帖最后由 nakar 于 2011-08-07 10:56 編輯

回復 2# pastebt


    真的很酷。

  1. D:\dev_py>dir c:tencent
  2. 驅動器 C 中的卷是 system
  3. 卷的序列號是 8CFF-C5EA

  4. C:\Program Files\tencent 的目錄

  5. 2011-08-01  14:17    <DIR>          .
  6. 2011-08-01  14:17    <DIR>          ..
  7. 2011-08-01  14:17    <DIR>          QQ
  8. 2011-06-26  14:54    <DIR>          QQIntl
  9. 2011-08-01  14:17    <DIR>          QQSoftMgr
  10.                0 個文件              0 字節(jié)
  11.                5 個目錄 16,137,007,104 可用字節(jié)
復制代碼

論壇徽章:
0
4 [報告]
發(fā)表于 2011-08-08 22:01 |只看該作者
回復 2# pastebt


    沒看懂你要說的啥意思,我試了兩個,是有不同的,但不知道為什么

論壇徽章:
0
5 [報告]
發(fā)表于 2011-08-09 01:44 |只看該作者
回復 4# linux_arm


    這個不是python的問題,是windows或者說dos的問題,你可以看看 這里,希望能幫你理解這個問題
http://en.wikipedia.org/wiki/Current_working_directory

論壇徽章:
0
6 [報告]
發(fā)表于 2011-08-09 08:52 |只看該作者
回復 5# pastebt
http://en.wikipedia.org/wiki/Current_working_directory
pastebt 發(fā)表于 2011-08-09 01:44

這能解釋lz的問題嗎?

論壇徽章:
0
7 [報告]
發(fā)表于 2011-08-09 10:15 |只看該作者
本帖最后由 ccporxy 于 2011-08-09 10:22 編輯

源碼跟進去發(fā)現 listdir 實際上是調用了win32 函數 FindFirstFile FindNextFile
來枚舉目錄信息。只不過會擴展一下傳入的路徑信息。

  1.             if (wch != L'/' && wch != L'\\' && wch != L':')
  2.                 wnamebuf[len++] = L'\\';
  3.             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).

原因就在此了~

論壇徽章:
0
8 [報告]
發(fā)表于 2011-08-09 11:16 |只看該作者
回復 7# ccporxy
這個基本上差不多了。FindFirstFile 要求系統(tǒng)目錄必須加\。
If you want to see files or get the attributes of a root directory, the following options would apply:

    To examine files in a root directory, you can use "C:\*" and step through the directory by using FindNextFile.
    To get the attributes of a root directory, use the GetFileAttributes function.

To examine a directory that is not a root directory, use the path to that directory, without a trailing backslash.

論壇徽章:
0
9 [報告]
發(fā)表于 2011-08-09 22:24 |只看該作者
感謝各位的答復~~受教了

論壇徽章:
0
10 [報告]
發(fā)表于 2011-08-10 09:54 |只看該作者
這個論壇果然牛人輩出啊
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯網協(xié)會會員  聯系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP