在python中,如何将文件复制到目录中,并在目录达到一定大小后停止。

|| 我对Python还是很陌生,但是我正在尝试创建一个程序,该程序除其他外将目录内容复制到适合光盘的一组目录中(我将以下变量设置为是我想要的容量大小,并设置一个输入语句以说明适用于哪一个):
BluRayCap = 25018184499
DVDCap = 4617089843
CDCap = 681574400
因此,基本上我想将开始目录的内容复制到另一个目录,并根据需要创建另一个目录,以使内容适合光盘。 我在这里遇到了障碍。谢谢!     
已邀请:
您可以使用os.path.getsize来获取文件的大小,还可以使用os.walk来遍历目录树,因此类似以下内容(我将让您实现CreateOutputDirectory和CopyFileToDirectory):
current_destination = CreateOutputDirectory()
for root, folders, files in os.walk(input_directory):
   for file in files:
       file_size = os.path.getsize(file)
       if os.path.getsize(current_destination) + file_size > limit:
          current_destination = CreateOutputDirectory()
       CopyFileToDirectory(root, file, current_destination)
另外,您可能会发现适用于Chrome的Python搜索扩展程序有助于查找本文档。     
Michael Aaron Safyan的答案很好。 此外,您可以将shutil模块用于
CreateOutputDirectory
CopyFileToDirectory
    

要回复问题请先登录注册