V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
qazwsxkevin
V2EX  ›  Python

请教复制、移动文件的方法?

  •  
  •   qazwsxkevin · Feb 13, 2020 · 3212 views
    This topic created in 2264 days ago, the information mentioned may be changed or developed.
    shutil.copyfile(),如果 dst 是一个多层级的目录,其中几层没有建立,
    shutil.copyfile()似乎并不支持直接创建,用什么更好的轮子可以直接完成呢?
    如果是移动文件呢?
    自己写 if os.path.exist()加上 os.mkdirs 也不是难的,只是小文件量大( 400 多万个小文件吧),前面已经做了很多 if 判断,感觉自己水平再写个东西去做判断,有拖腿感觉.
    5 replies    2020-02-13 19:05:33 +08:00
    milu123
        1
    milu123  
       Feb 13, 2020
    fs-extra 库有 ensureDir 方法
    https://www.npmjs.com/package/fs-extra
    wuwukai007
        2
    wuwukai007  
       Feb 13, 2020
    shutil.copytree 应该可以复制多层目录的
    leido
        3
    leido  
       Feb 13, 2020 via Android
    二楼正解
    v22ex6667
        4
    v22ex6667  
       Feb 13, 2020
    直接调用系统的 复制,移动效率如何?
    yzwduck
        5
    yzwduck  
       Feb 13, 2020
    试试调用外部工具? Windows 有 FastCopy,其他系统基本都有 rsync。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5249 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:16 · PVG 09:16 · LAX 18:16 · JFK 21:16
    ♥ Do have faith in what you're doing.