python修改文件名的renname和renames方法使用规则

os.rename(src, dst)

  os.rename() 方法用于命名文件或目录,src、dst均为路径字符串,从 src 到 dst,如果dst是一个存在的目录, 将抛出OSError。
  需要注意的是这两个参数可以是绝对路径,也可以是相对路径,相对路径是相对于os.getcwd()的路径,通常在idle中使用,真正写成python文件不建议使用。

os.renames(src, dst)

  os.renames() 用法和上述一致,但它功能更强大,它不仅能够修改指定的目录或文件,还能修改上层的目录或上上层,这就是说明手册中的解释,一直递归修改。例如:

os.renames("F:\\haha\\test1\\test2\\3.txt","F:\\haha\\test4\\test5\\6.txt")
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ERROR: Exception: Traceback (most recent call last): File "c:\program files\python\lib\shutil.py", line 788, in move os.rename(src, real_dst) PermissionError: [WinError 5] 拒绝访问。: 'c:\\program files\\python\\lib\\site-packages\\flask-1.1.2.dist-info\\' -> 'C:\\Users\\弦引\\AppData\\Local\\Temp\\pip-uninstall-0g0yzsps' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\弦引\AppData\Roaming\Python\Python38\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapper status = run_func(*args) File "C:\Users\弦引\AppData\Roaming\Python\Python38\site-packages\pip\_internal\commands\uninstall.py", line 105, in run uninstall_pathset = req.uninstall( File "C:\Users\弦引\AppData\Roaming\Python\Python38\site-packages\pip\_internal\req\req_install.py", line 687, in uninstall uninstalled_pathset.remove(auto_confirm, verbose) File "C:\Users\弦引\AppData\Roaming\Python\Python38\site-packages\pip\_internal\req\req_uninstall.py", line 381, in remove moved.stash(path) File "C:\Users\弦引\AppData\Roaming\Python\Python38\site-packages\pip\_internal\req\req_uninstall.py", line 272, in stash renames(path, new_path) File "C:\Users\弦引\AppData\Roaming\Python\Python38\site-packages\pip\_internal\utils\misc.py", line 318, in renames shutil.move(old, new) File "c:\program files\python\lib\shutil.py", line 800, in move rmtree(src) File "c:\program files\python\lib\shutil.py", line 737, in rmtree return _rmtree_unsafe(path, onerror) File "c:\program files\python\lib\shutil.py", line 615, in _rmtree_unsafe onerror(os.unlink, fullname, sys.exc_info()) File "c:\program files\python\lib\shutil.py", line 613, in _rmtree_unsafe os.unlink(fullname) PermissionError: [WinError 5] 拒绝访问。: 'c:\\program files\\python\\lib\\site-packages\\flask-1.1.2.dist-info\\entry_points.txt'
07-22

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值