os.path.abspath(path)-----------------#返回絕對路徑
os.path.basename(path)-----------------#返回文件名
os.path.commonprefix(list) -----------------#返回list(多個路徑)中戳玫,所有path共有的最長的路徑待讳。
os.path.dirname(path)----------------- #返回文件路徑
os.path.exists(path) -----------------#路徑存在則返回True,路徑損壞返回False
os.path.lexists? -----------------? ? #路徑存在則返回True,路徑損壞也返回True
os.path.expanduser(path)? -----------------? ? #把path中包含的"~"和"~user"轉(zhuǎn)換成用戶目錄
os.path.expandvars(path)? -----------------? ? #根據(jù)環(huán)境變量的值替換path中包的”$name”和”${name}”
os.path.getatime(path)? -----------------? ? #返回最后一次進入此path的時間。
os.path.getmtime(path)? -----------------? ? #返回在此path下最后一次修改的時間。
os.path.getctime(path)? ? ? -----------------? ? #返回path的大小
os.path.getsize(path)? -----------------? ? ? #返回文件大小,如果文件不存在就返回錯誤
os.path.isabs(path)? ? ? -----------------? ? ? ? #判斷是否為絕對路徑
os.path.isfile(path)? ? ? -----------------? ? #判斷路徑是否為文件
os.path.isdir(path)? ? ? -----------------? ? #判斷路徑是否為目錄
os.path.islink(path)? ? -----------------? ? ? #判斷路徑是否為鏈接
os.path.ismount(path)? ? ? -----------------? #判斷路徑是否為掛載點()
os.path.join(path1[, path2[, ...]])? -----------------? ? #把目錄和文件名合成一個路徑
os.path.normcase(path)? ----------------- ? ?#轉(zhuǎn)換path的大小寫和斜杠
os.path.normpath(path)? -----------------? ? #規(guī)范path字符串形式
os.path.realpath(path)? -----------------? #返回path的真實路徑
os.path.relpath(path[, start])? -----------------? #從start開始計算相對路徑
os.path.samefile(path1, path2)? --------------- #判斷目錄或文件是否相同
os.path.sameopenfile(fp1, fp2)? ----------------#判斷fp1和fp2是否指向同一文件
os.path.samestat(stat1, stat2)? ----------- ?#判斷stat tuple stat1和stat2是否指向同一個文件
os.path.split(path)? -----------------? ? ? #把路徑分割成dirname和basename,返回一個元組
os.path.splitdrive(path)? -----------------? #一般用在windows下轻猖,返回驅(qū)動器名和路徑組成的元組
os.path.splitext(path)? -----------------? #分割路徑,返回路徑名和文件擴展名的元組
os.path.splitunc(path)? -----------------? #把路徑分割為加載點與文件
os.path.walk(path, visit, arg)? ------------ #遍歷path域那,進入每個目錄都調(diào)用visit函數(shù)咙边,visit函數(shù)必須有3個參數(shù)(arg, dirname, names),dirname表示當(dāng)前目錄的目錄名次员,names代表當(dāng)前目錄下的所有文件名败许,args則為walk的第三個參數(shù)
os.path.supports_unicode_filenames ? ----------------- #設(shè)置是否支持unicode路徑名
下面是os.path.exists(path)的例子: