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'......]
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'......]
相关文章推荐
- Python——os.path.dirname(__file__) 与 os.path.join(str,str)
- 详解Python中的join()函数的用法(字符串和os.path)
- python路径拼接os.path.join()函数完全教程
- python str.join 和 os.path.join
- Python中的join()函数的用法(字符串和os.path)
- Python os.path.join方法 join方法
- python中的join()与os.path.join()的使用方式
- Python join() 方法与os.path.join()的区别
- Python os.path.dirname(__file__) os.path.join(str,str)
- python基础(一)--join和os.path.join函数的用法以及字符串格式化
- python使用os.walk和os.path.join来遍历文件夹的文件(包括子文件夹下的文件)
- 详解Python中的join()函数的用法(字符串和os.path)
- python的os.path.join
- python使用os.walk和os.path.join来遍历文件夹的文件(包括子文件夹下的文件)
- python的os.path.join()参数是绝对路径的问题
- python使用os.walk和os.path.join来遍历文件夹的文件(包括子文件夹下的文件)
- bafe Python 3.6:join() 方法与os.path.join()的区别
- Python中.join()和os.path.join()两个函数的用法详解
- Python中join()和os.path.join()的区别
- 浅谈python中拼接路径os.path.join斜杠的问题