V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
getlost
V2EX  ›  Python

系统是 win10,在自学的《 Python 简明教程》,今天学到教程里的备份程序,程序跑通了,但是没有在 test 文件里找到备份的文件。cmd 也试过,还是没有

  •  
  •   getlost · 2018-01-31 22:07:36 +08:00 · 3320 次点击
    这是一个创建于 2267 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import os
    import time

    source = [' d:\\Doc']

    target_dir = ' d:\\test '

    target = target_dir + os.sep + \
    time.strftime('%Y%m%d%H%M%S') + ' .zip'


    zip_command = 'zip -r {0} {1}'.format(target,
    ' '.join(source))

    print('zip command is:')
    print(zip_command)
    print('go')
    if os.system(zip_command) == 0:
    print('s', target)
    else:
    print('bb')
    第 1 条附言  ·  2018-02-01 22:08:58 +08:00
    zip command is:
    zip -r d:\test \20180201220751.zip "d:\Doc" d:\Doc1 (这里稍微有改动)
    go
    zip warning: name not matched: \20180201220751.zip
    updating: Doc/ (260 bytes security) (stored 0%)
    updating: Doc/python361.chm (172 bytes security) (deflated 0%)
    updating: Doc1/ (260 bytes security) (stored 0%)
    updating: Doc/22.txt (172 bytes security) (stored 0%)
    updating: Doc1/�½� Second Scan document.s2 (172 bytes security) (stored 0%)
    s d:\test \20180201220751.zip

    这是运行结果
    15 条回复    2018-02-01 23:54:01 +08:00
    yichinzhu
        1
    yichinzhu  
       2018-01-31 22:37:17 +08:00
    windows 没有 zip 这个命令
    tennc
        2
    tennc  
       2018-01-31 22:53:16 +08:00
    你在 cmd 下 可以 用 zip 命令??
    安装个 7z 然后在用过 7z 命令吧~~
    HuaBeau
        3
    HuaBeau  
       2018-01-31 23:06:28 +08:00
    楼主仔细看下书,书上有如下内容:
    https://bop.mol.uno/13.problem_solving.html
    针对 Windows 用户的提示
    Windows 用户可以从 GnuWin32 项目页面( http://gnuwin32.sourceforge.net/packages/zip.htm ) 上下载并安装 zip 命令,并将 C:\Program Files\GnuWin32\bin 添加至你的系统的 PATH 环境变量中,这一操作过程与我们为使系统识别 Python 命令本身所做的事情相同。
    omph
        4
    omph  
       2018-01-31 23:10:32 +08:00
    装个 7zip,然后指定命令路径即可
    zyqf
        5
    zyqf  
       2018-02-01 09:12:12 +08:00 via Android
    感觉 Windows 下写 Python 程序怪怪的。
    ntuwang
        6
    ntuwang  
       2018-02-01 09:18:54 +08:00
    楼主还是 换 mac 或者 Linux 桌面发行版 吧,学 python 来噻
    strive
        7
    strive  
       2018-02-01 16:35:46 +08:00
    装一个 winrar
    strive
        8
    strive  
       2018-02-01 16:37:05 +08:00
    @strive 用 start winner a 这个命令
    getlost
        9
    getlost  
    OP
       2018-02-01 21:47:23 +08:00
    @yichinzhu 谢谢你,我按照作者的提示装了 zip
    getlost
        10
    getlost  
    OP
       2018-02-01 21:50:13 +08:00
    @tennc 写好程序保存之后,在 cmd 里运行这个程序(我很白,以为在 pycharm 跑和 cmd 里不一样)
    getlost
        11
    getlost  
    OP
       2018-02-01 21:51:12 +08:00
    @HuaBeau 嗯,就是按照这个装了 zip 的,但是没在备份文件里找到压缩的文件
    getlost
        12
    getlost  
    OP
       2018-02-01 21:53:21 +08:00
    @omph 嗯,谢谢你,但是了解一点的就是 python 了,其他都不会。我去查查
    getlost
        13
    getlost  
    OP
       2018-02-01 21:55:27 +08:00
    @zyqf 之前装过乌班图,但是不会用,一直没法联网,又要忙着毕设就删了。毕业之后想学学 python
    getlost
        14
    getlost  
    OP
       2018-02-01 22:09:08 +08:00
    @strive 在 cmd 里用吗?
    omph
        15
    omph  
       2018-02-01 23:54:01 +08:00
    zip -r d:\test \20180201220751.zip
    你的路径里多了个空格吧?
    有空格应该用引号
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1396 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:51 · PVG 07:51 · LAX 16:51 · JFK 19:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.