close

os.getcwd()

http://www.tutorialspoint.com/python/os_getcwd.htm

回傳當前工作目錄 (把檔案所在的路徑抓出來)

returns current working directory of a process

範例:

import os
path =  os.getcwd()
print path
C:\Python27

 

os.listdir()

http://www.tutorialspoint.com/python/os_listdir.htm

回傳目錄底下的所有檔案名稱列表(list) (抓資料夾裡的所有檔案名稱)

returns a list containing the names of the entries in the directory given by path

import os
path =  os.getcwd()
dirs = os.listdir(path)
print dirs
['DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'NEWS.txt', 'python.exe', 'pythonw.exe', 'README.txt', 'Scripts', 'tcl', 'Tools']

arrow
arrow
    全站熱搜

    恩比柿 發表在 痞客邦 留言(0) 人氣()