您的位置:首页 > 编程语言 > Python开发

Python os.path.join

2015-02-27 08:44 393 查看
API文档:

os.path.join(path1[, path2[, ...]])

Join one or more path components intelligently. If any component is an absolute path, all previous components (on Windows, including the previous drive letter, if there was one) are thrown away, and joining continues. The return value is the concatenation of
path1, and optionally path2, etc., with exactly one directory separator (os.sep) inserted between components, unless path2 is empty. Note that on Windows, since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative
to the current directory on drive C: (c:foo), not c:\foo.

翻译文档:

连接一个或多个文件路径,例如:os.path.join('c:/',''foo'),输出:c:/foo

例子:

#! /usr/bin/env python

#coding=utf-8

import os

pathStr = 'c:/'

fList = [os.path.normcase(el) for el in os.listdir(pathStr)]

fList = [os.path.join(pathStr,f) for f in fList]

print fList

输出:

['c:/$recycle.bin', 'c:/360downloads'......]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: