From d11df4e7ce4bebd8b20a6a55d3b926f61acd42c6 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 11 Jul 2018 15:25:06 +0200 Subject: [PATCH] check for filename dupes on drive --- drive-download | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drive-download b/drive-download index 203ac08..bbc133a 100755 --- a/drive-download +++ b/drive-download @@ -7,6 +7,7 @@ if sys.version_info < (3, 3): sys.stderr.write("Sorry, requires at least Python 3.3\n") sys.exit(1) +import collections import os import pickle import shlex @@ -25,7 +26,15 @@ gauth.CommandLineAuth() drive = GoogleDrive(gauth) file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(FOLDER)}).GetList() -# XXX Check for filename dupes + +file_names = [f['title'] for f in file_list] +file_names_dupes = [f for f, count in collections.Counter(file_names).items() if count > 1] +if len(file_names_dupes) > 0: + print('Duplicate filenames on Drive!') + for fn in sorted(file_names_dupes): + print(fn) + sys.exit(1) + for file1 in file_list: if file1['mimeType'] == 'application/vnd.google-apps.folder': continue