如何使用Python将zipfile从一个文件夹复制到另一个文件夹

时间:2020-01-16 15:32:26

标签: python

请不要将问题标记为重复。我已经尝试了多个问题,但对我没有用。因此,我提出了一个新问题。

问题:

我正在尝试将zip文件列表从源复制到目标文件夹。我尝试使用shutil.copy和shutil.copyfile,但是我看不到文件被复制到目标文件夹中。如果我做错了什么,或者还有其他处理zip文件的方法,有人可以帮我吗?以下是我的脚本,执行脚本时没有看到任何错误。我正在Linux机器上运行。

        dt.DefaultView.Sort = "ID";
        int horizontal = 0;
        int vertical = 0;
        Button[] buttonArray = new Button[dt.Rows.Count];

        for (int items = 0; items < buttonArray.Length; items++)
        {
            buttonArray[items] = new Button();
            buttonArray[items].Size = new Size(150, 50);
            buttonArray[items].Location = new Point(horizontal, vertical);
            buttonArray[items].Name = string.Format("Button_{0}", dt.DefaultView[items].Row["ID"].ToString());
            buttonArray[items].Text = dt.DefaultView[items].Row["Name"].ToString();
            buttonArray[items].Click += btn_msg;

            if ((items + 1) < buttonArray.Length)
            {
                vertical += 50;
            }

            flowLayoutPanel_AttackName.Controls.Add(buttonArray[items]);
        }

尝试过的问题

  1. How do I copy an entire directory of files into an existing directory using Python?
  2. How do I copy a file in Python?
  3. How to copy a file to a specific folder in a Python script?

1 个答案:

答案 0 :(得分:1)

问题出在函数source的{​​{1}}中,因此将shutil.copy更改为shutil.copy(file, destination)

尝试下面的代码,

shutil.copy(os.path.join(source, file), destination)
相关问题