使用os x在python 3中创建一个.zip文件进行备份(create a .zip file for backup in python 3 with os x)
我是编程python的新手(现在是5天)并遇到了一个问题,我似乎无法在这个论坛中找到答案。 我将不胜感激任何帮助和非常感谢。
成为。 我在macbook pro上使用python 3。 我正在使用一个名为“komodo edit”的编辑器,我正在使用CH Swaroop的“Byte of Python”作为指南。
我遇到的问题是创建一个程序的示例,该程序从一个文件夹获取文件并将其作为zip文件备份到另一个文件夹。
书中的例子如下:
Save as backup_ver1.py: import os import time # The files and directories to be backed up are specified in a list. source = ['"C:\\My Documents"', 'C:\\Code'] # Notice we had to use double quotes inside the string for names with spaces in it. # The backup must be stored in a main backup directory target_dir = 'E:\\Backup' # Remember to change this to what you will be using # The files are backed up into a zip file. # The name of the zip archive is the current date and time target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip' # We use the zip command to put the files in a zip archive zip_command = "zip -qr {0} {1}".format(target, ' '.join(source)) # Run the backup if os.system(zip_command) == 0: print('Successful backup to', target) else: print('Backup FAILED')
我的代码如下
import os import time source = ['C:\\learningPython','C:\\scan'] # can i use / instead of the \? # why is square brackets used here? i'm under the assumption the square brackets are used for list. i'm also assuming one is the directory and the other is the file. target_dir = 'C:/backup' # created a "backup" folder target = target_dir + os.sep +time.strftime('%Y%M%D%H%M%S') + '.zip' zip_command = "zip -qr {0} {1}".format(target, ‚ ‚.join(source)) if os.system(zip_command) == 0: print(‚Successful backup to‚, target) else: print(‚Backup FAILED‚)
我得到了
zip错误:无所事事! (尝试:zip -qr C:/backup/20133201/15/13203219.zip.-i C:learningPythonC:scan)备份失败
I am new to programing python (5 days now) and have ran into a problem that i can't seem to find the answer to in this forum. i would appreciate any help and a detailed explaination would be very much appreciated.
To being. i'm using python 3 on a macbook pro. i'm using an editor called "komodo edit" I'm using CH Swaroop's "Byte of Python" as a guide.
the problem i'm having is with an example of creating a program that takes a file from one folder and backs it up to another as a zip file.
the example in the book is as follows:
Save as backup_ver1.py: import os import time # The files and directories to be backed up are specified in a list. source = ['"C:\\My Documents"', 'C:\\Code'] # Notice we had to use double quotes inside the string for names with spaces in it. # The backup must be stored in a main backup directory target_dir = 'E:\\Backup' # Remember to change this to what you will be using # The files are backed up into a zip file. # The name of the zip archive is the current date and time target = target_dir + os.sep + time.strftime('%Y%m%d%H%M%S') + '.zip' # We use the zip command to put the files in a zip archive zip_command = "zip -qr {0} {1}".format(target, ' '.join(source)) # Run the backup if os.system(zip_command) == 0: print('Successful backup to', target) else: print('Backup FAILED')
my code is as follows
import os import time source = ['C:\\learningPython','C:\\scan'] # can i use / instead of the \? # why is square brackets used here? i'm under the assumption the square brackets are used for list. i'm also assuming one is the directory and the other is the file. target_dir = 'C:/backup' # created a "backup" folder target = target_dir + os.sep +time.strftime('%Y%M%D%H%M%S') + '.zip' zip_command = "zip -qr {0} {1}".format(target, ‚ ‚.join(source)) if os.system(zip_command) == 0: print(‚Successful backup to‚, target) else: print(‚Backup FAILED‚)
I get a
zip error: Nothing to do! (try: zip -qr C:/backup/20133201/15/13203219.zip . -i C:learningPythonC:scan) backup failed
原文:https://stackoverflow.com/questions/14350222
最满意答案
我安装了电动工具......
http://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f
...然后在我的上下文菜单中显示“高级” - >“查看方式”。
I installed the Power Tools...
http://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f
... and then in my context menu "Advanced" --> "View With" appeared.
相关问答
更多-
好吧,我想通了 - 源代码管理资源管理器在Visual Studio IDE中作为命令( View.TfsSourceControlExplorer )提供,而Visual Studio可执行文件(devenv.exe)在IDE启动后提供/ Command参数来执行命令。 在我的情况下,我用下面的命令行创建了一个桌面快捷方式: "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" /Com ...
-
这意味着该对象上存在挂起的重命名: It means that there is a pending rename on that object:
-
在Visual Studio 2012中打开TFS源代码管理资源管理器的热键?(Hotkey to open TFS Source Control Explorer in Visual Studio 2012?)[2023-06-14]
尝试以下步骤: 转到工具菜单选项 从环境中选择键盘 从显示命令中选择View.TfsSourceControlExplorer 包含: 。 您可以在文本框中键入View.TFS来过滤列表。 在按shorcut keys =>点击分配输入您的热键 希望有帮助! Try with below step: Go to Options of Tools menu Select the Keyboard from Environment Select View.TfsSourceControlExplorer fro ... -
如何在Visual Studio 2013 IDE中添加工作项标签?(How to add a work item tag within Visual Studio 2013 IDE?)[2023-10-30]
在Update 2中启用了在Visual Studio 2013中添加和编辑标签。 我目前正在运行Visual Studio 2013 Update 4,并且该功能在那里可用。 确保您下载并安装最新版本的Visual Studio 2013以访问最新商品 。 Adding and editing tags in Visual Studio 2013 has been enabled in Update 2. I'm currently running Visual Studio 2013 Update 4 ... -
无法在Visual Studio 2013中编辑签出文件(TFS)(Cannot edit checked out file (TFS) in Visual Studio 2013)[2022-08-06]
我暂停了Resharper并重新启动了Visual Studio 2013。一旦我重新打开它,问题就消失了。 恢复Resharper导致问题再次出现。 解决方案是相当大的,也许就是这样。 在将Resharper置于暂停模式之前,我尝试关闭代码分析,认为工作量太大,但这没有帮助。 虽然暂停了 我希望这有助于其他任何人遇到同样的问题。 所有我现在要做的就是弄清楚如何让Resharper回到游戏中,而不会出现问题。 我们依靠Resharper,因为它是一个很棒的工具。 由于该解决方案有许多项目,我将尝试使用我的W ... -
通常,“覆盖所有文件,即使本地版本与指定版本匹配”选项也会执行类似“用源代码管理中的内容覆盖所有文件”的内容。 有关详细信息,请参阅MSDN中的“ 获取团队项目源 ”链接: 7.(可选)即使本地版本与指定的版本选项匹配,也选择“覆盖所有文件”。 如果选中,则服务器中的文件将覆盖所有文件。 并查看此博客中的问题: 为什么“获取最新”有时不... Usually, "Overwrite all files even if the local version matches the specified versi ...
-
我安装了电动工具...... http://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f ...然后在我的上下文菜单中显示“高级” - >“查看方式”。 I installed the Power Tools... http://visualstudiogallery.msdn.microsoft.com/f017b10c-02b4-4d6d-9845-58a06545627f ... and then ...
-
总之,不,在Visual Studio 2017中没有内置的对git的UI支持。 或者,您可以根据您的源代码管理设置尝试以下扩展。 在Visual Studio中,选择工具 > 扩展和更新 ,在左侧窗格中选择联机 ,在右上方的搜索栏中搜索以下内容之一: Bitbucket >安装Visual Studio Bitbucket扩展 GitHub > 为Visual Studio安装GitHub Extnesion Git >安装Easy Git集成工具 前两者在提供UI控件方面做得很好,与源代码控件一起工作, ...
-
TFS 2012 Source Control Explorer仅显示我的结账(TFS 2012 Source Control Explorer only shows my check outs)[2022-04-14]
多么令人尴尬......我们只是想通了。 团队项目允许多次结账,因此我们能够检查文件是有道理的,问题是我们无法看到对方检出的文件。 我的部分问题是我在团队资源管理器中打开了“团队项目1”,但是在Visual Studio中打开了“团队项目2”的解决方案。 所以我认为这就是为什么我看不到“Change Source Control”选项。 一旦我在团队资源管理器中更改了团队项目,我就能看到“更改源代码管理”选项(文件|源代码管理|高级|更改源代码管理)。 打开“更改源代码管理”屏幕后,我看到我的解决方案和项目 ... -
好的,解决了。 所有缺少的是项目级别的“撤消待定更改”。 这个操作完成后项目就没了:) Ok, solved. All what was missing is "Undo pending changes" at project-level. After this operation the project is gone :)