python os.chdir()的使用

951次阅读
没有评论

python

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

2、语法为os.chdir(path)。

3、参数path,要切换到的新路径。

4、返回值,如果允许访问返回True,否则False。

python os.chdir()实例

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()的使用,希望对大家有所帮助。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-04-13发表,共计402字。
新手QQ群:570568346,欢迎进群讨论 Python51学习