后浪云Python教程:python os.chdir()的使用
1、os.chdir()()用于改变当前工作目录到指定的路径。
2、语法为os.chdir(path)。
3、参数path,要切换到的新路径。
4、返回值,如果允许访问返回True,否则False。
实例
import os os.chdir('G:/阿里云盘/音乐/') datanames = os.listdir() print(datanames) for file in datanames: if ' - ' in file: new_name = file.replace(' - ', '') os.rename(file, new_name) print(file + ' 已改为 ' + new_name) else: pass
以上就是python os.chdir()的使用,希望对大家有所帮助。更多Python学习指路:后浪云python教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
版权声明:
作者:后浪云
链接:https://www.idc.net/help/176335/
文章版权归作者所有,未经允许请勿转载。
THE END