How to modify the folder name in Python
Use theos.rename()method to modify the folder name in Python.
Recommended learning:Python video tutorial
Syntax:
os.rename(src, dst)
Parameters:
src -- the directory name to be modified
dst -- the modified directory name
Usage example:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 列出目录 print "目录为: %s"%os.listdir(os.getcwd()) # 重命名 os.rename("test","test2") print "重命名成功。" # 列出重命名后的目录 print "目录为: %s" %os.listdir(os.getcwd())
The output result of executing the above program is:
目录为: [ 'a1.txt','resume.doc','a3.py','test' ] 重命名成功。 [ 'a1.txt','resume.doc','a3.py','test2' ]
PHP Chinese website, a large number ofIntroduction to Programmingtutorials, welcome to learn!
The above is the detailed content of How to modify the folder name in Python. For more information, please follow other related articles on the PHP Chinese website!