Python文件或目录操作的常用函数
2013-09-11 19:23
731 查看
◆ os.listdir(path)
Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the directory.
◆ os.getcwd() method displays the current working directory
◆ os.chdir() method to change the current directory
◆ other file and directory operation functions:
os.rename(current_file_name, new_file_name)
os.remove(file_name)
os.mkdir("newdir")
os.rmdir('dirname')
◆ 内置变量__file__可以获得文件名(有可能是相对路径名),进一步调用 os.path.realpath(__file__)可以获得该文件的路径完整路径名(并且已经展开链接文件)。
◆ os.path.dirname(filename)可以获得文件所在的目录名。
◆ os.path.basename(filename)可以获得完整路径名最后的文件名,如果是一个目录,则返回""。
◆ os.path.join(path1, path2)可以将多个路径参数连接,这也是一个常用的函数。
◆ os.curdir和os.pardir是两个常量字符串:"."和"..",分别表示当前目录和上一级目录的字符串。
◆ 获取当前程序所在目录的完整路径
_curpath=os.path.normpath( os.path.join( os.getcwd(), os.path.dirname(__file__) ) )
Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the directory.
◆ os.getcwd() method displays the current working directory
◆ os.chdir() method to change the current directory
◆ other file and directory operation functions:
os.rename(current_file_name, new_file_name)
os.remove(file_name)
os.mkdir("newdir")
os.rmdir('dirname')
◆ 内置变量__file__可以获得文件名(有可能是相对路径名),进一步调用 os.path.realpath(__file__)可以获得该文件的路径完整路径名(并且已经展开链接文件)。
◆ os.path.dirname(filename)可以获得文件所在的目录名。
◆ os.path.basename(filename)可以获得完整路径名最后的文件名,如果是一个目录,则返回""。
◆ os.path.join(path1, path2)可以将多个路径参数连接,这也是一个常用的函数。
◆ os.curdir和os.pardir是两个常量字符串:"."和"..",分别表示当前目录和上一级目录的字符串。
◆ 获取当前程序所在目录的完整路径
_curpath=os.path.normpath( os.path.join( os.getcwd(), os.path.dirname(__file__) ) )
相关文章推荐
- python常用的文件目录操作函数
- Python文件或目录操作的常用函数
- Python文件或目录操作的常用函数
- python对文件,目录,操作函数
- Delphi 文件、目录等常用操作函数 - delphi - gliethttp
- Python OS 文件操作模块常用函数
- Python中shutil模块的常用文件操作函数用法示例
- Python 中针对文件和目录(文件夹)的常用操作
- os、os.path 模块中关于文件、目录常用的函数使用方法(python)
- python 常用对linux系统文件及目录的操作
- python文件目录操作常用方法总结
- Python OS 文件操作模块常用函数
- python-文件操作及os模块常用函数
- [转]python常用文件及目录操作
- Python 文件操作常用函数
- python os模块常用操作文件目录方法
- python文件和目录操作函数小结
- Python----文件/目录的常用管理操作
- Python OS 文件操作模块常用函数
- Python之文件操作及常用函数