मुझे पता है कि यह (थोड़ी देर) देर हो चुकी है, लेकिन किसी और के लिए जो इस प्रश्न में ठोकर खाती है और एक ही समस्या है ... मेरी समस्या विशेष रूप से यह है कि मेरे पास सैकड़ों गीगा की आवश्यकता नहीं है ड्रॉपबॉक्स सर्वर और मैं चुनिंदा सिंक के साथ उन्हें हटाने में सक्षम होने के लिए सिर्फ एक HDD को साफ़ नहीं करना चाहता हूं।
वेब फ़ाइलों से अभी भी कई फाइलें संभव नहीं हैं, लेकिन यदि आपको Dropbox API में डाइविंग नहीं लगता है तो यह कम से कम स्वचालित हो सकता है और आपको अपना स्वयं का संग्रहण उपयोग नहीं करना पड़ेगा (मैंने यह किया Python SDK के साथ नीचे, लेकिन अन्य भाषा विकल्प भी हैं)। फ़ाइल सीमा अभी भी लागू होती है, लेकिन प्रत्येक निर्देशिका में फ़ाइलों की संख्या को अंक में चलाने के बिना उन्हें हटाने का उचित तरीका निर्धारित करने के लिए गिना जा सकता है। इस तरह:
निम्न स्क्रिप्ट आपकी अद्वितीय ड्रॉपबॉक्स एपीआई कुंजी और ड्रॉपबॉक्स निर्देशिकाओं (deleteDirList
) की सूची इनपुट के रूप में लेती है। यह deleteDirList
के प्रत्येक तत्व की प्रत्येक उपनिर्देशिका के माध्यम से लूप करता है यह निर्धारित करने के लिए कि सीमा को मारने के बिना निर्देशिका को हटाने में सक्षम होने के लिए कुछ पर्याप्त फ़ाइलें हैं (मैंने रूढ़िवादी (?) 10,000 फ़ाइलों को सीमा निर्धारित की है); यदि बहुत सारी फाइलें हैं, तो यह गिनती सीमा से नीचे होने तक फ़ाइलों को व्यक्तिगत रूप से हटा देती है। आप अजगर पैकेज dropbox
(मैं एनाकोंडा उपयोग करते हैं, तो conda install dropbox
)
भालू मन में यह एक जानवर बल दृष्टिकोण है स्थापित करने के लिए की आवश्यकता होगी; प्रत्येक उपनिर्देशिका को एक-एक करके हटा दिया जाता है जो लंबे समय तक ले सकता है। प्रत्येक उपनिर्देशिका में फ़ाइलों को गिनने के लिए एक बेहतर तरीका होगा, फिर उच्चतम-स्तरीय निर्देशिका निर्धारित करें जिसे सीमा को मारने के बिना हटाया जा सकता है, लेकिन दुर्भाग्यवश मेरे पास इस समय लागू करने का समय नहीं है।
import dropbox
##### USER INPUT #####
appToken = r'DROPBOX APIv2 TOKEN'
deleteDirList = ['/directoryToDelete1/','/directoryToDelete2/'] # list of Dropbox paths in UNIX format (where Dropbox root is specified as '/') within which all contents will be deleted. The script will go through these one at a time. These need to be separate directories; subdirectories will deleted in the loop and will throw an exception if listed here.
######################
dbx = dropbox.Dropbox(appToken)
modifyLimit = 10000
# Loop through each path in deleteDirList
for deleteStartDir in deleteDirList:
deleteStartDir = deleteStartDir.lower()
# Initialize pathList. This is the variable that records all directories down each path tree so that each directory is traversed, files counted, then deleted
pathList = [deleteStartDir]
# Deletion loop
try:
while 1:
# Determine if there is a subdirectory in the current directory. If not, set nextDir=False
nextDir = next((x.path_lower for x in dbx.files_list_folder(pathList[-1]).entries if isinstance(x,dropbox.files.FolderMetadata)),False)
if not not nextDir: # if nextDir has a value, append the subdirectory to pathList
pathList.append(nextDir)
else: # otherwise, delete the current directory
if len(pathList)<=1: # if this is the root deletion directory (specified in deleteDirList), delete all files and keep folder
fileList = [x.path_lower for x in dbx.files_list_folder(pathList[-1]).entries]
print('Cannot delete start directory; removing final',len(fileList),'file(s)')
for filepath in fileList:
dbx.files_delete(filepath)
raise EOFError() # deletion script is complete
# Count the number of files. If fileCnt>=modifyLimit, remove files until fileCnt<modifyLimit, then delete the remainder of the directory
fileCnt = len(dbx.files_list_folder(pathList[-1]).entries)
if fileCnt<modifyLimit:
print('Deleting "{path}" and'.format(path=pathList[-1]),fileCnt,'file(s) within\n')
else:
print('Too many files to delete directory. Deleting',fileCnt-(modifyLimit+1),'file(s) to reduce count, then removing',pathList[-1],'\n')
fileList = [x.path_lower for x in dbx.files_list_folder(pathList[-1]).entries]
for filepath in fileList[-modifyLimit:]:
dbx.files_delete(filepath)
dbx.files_delete(pathList[-1])
del pathList[-1]
except EOFError:
print('Deleted all relevant files and directories from "{}"'.format(deleteStartDir))
30,000 फ़ाइलों का कुल आकार क्या है? – Flukey
@ फ्लाकी: शायद 500 एमबी से 1 जीबी तक। वे बहुत छोटे हैं। – Zach
मैंने इसे चूसने और फ़ाइलों को सभी मशीनों पर डाउनलोड करने के लिए 12 घंटे का इंतजार करके हल किया। तब मैंने उन्हें हटा दिया, और चीजें अब peachy हैं। – Zach