成都网站建设设计

将想法与焦点和您一起共享

创新互联Python教程:pythonos.chdir()的使用

1、os.chdir()()用于改变当前工作目录到指定的路径。

从事双线服务器托管,服务器租用,云主机,网站空间,域名与空间,CDN,网络代维等服务。

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电脑。


本文题目:创新互联Python教程:pythonos.chdir()的使用
链接URL:https://chengdu.cdxwcx.cn/article/dpiohsj.html