适用于google.datalab.storage的Python-检查文件是否成功复制

时间:2018-08-24 18:21:36

标签: python google-cloud-storage

在Google Cloud Storage Bucket中,我正在尝试将文件从其原始文件夹移至存档文件夹。一旦文件移动“成功”完成,我想从其原始文件夹中删除文件。

## Assigning the bucket to the bucket object
bucket = storage.Bucket(<Bucket_Name>)

## Enumerating and finding the required file object in the bucket and 
##assigning that to my_file object
for obj in bucket.objects():
 if obj.key.find(<file_name>) > 0:
 my_file = obj
 print(my_file.key)

## Taking the current timestamp
timestamp = str(datetime.now())

## Copying the file to the new location
my_file.copy_to( <archive folder> + <file name> + <timestamp>)

我现在要在删除文件对象之前检查“ my_file.copy_to()”是否已成功执行。我该如何检查?

1 个答案:

答案 0 :(得分:0)

您可以使用返回的Blob对象中的time_createdexists属性。