나는 이것이 (조금) 늦었다 고 알고 있지만,이 질문에 걸려 넘어지면서 같은 문제가있는 다른 사람을 위해 ... 내 문제는 특별히 내가 필요로하는 파일이 수백 개 밖에 없다는 것입니다. Dropbox 서버와 나는 선택적 동기화로 HDD를 삭제할 수 없도록 HDD를 정리하고 싶지 않습니다.
많은 파일을 여전히 삭제할 수는 없지만 Dropbox API으로 들어가기를 원한다면 적어도 자동으로 수행 할 수 있으므로 자신의 저장소를 사용할 필요가 없습니다. 아래는 Python SDK이지만 다른 언어 옵션도 있습니다). 파일 제한은 계속 적용되지만 각 디렉토리의 파일 수를 계산하여 문제를 해결하지 않고 파일을 삭제하는 적절한 방법을 결정할 수 있습니다. 마찬가지로 :
다음 스크립트는 고유 한 Dropbox API 키와 Dropbox 디렉토리 목록 (deleteDirList
)을 입력으로 사용합니다. 그런 다음 각 요소의 각 하위 디렉토리 (deleteDirList
)를 반복하여 제한을 두지 않고 디렉토리를 삭제할 수있는 파일이 부족한 지 확인합니다 (보수적 인 (?) 10,000 개의 파일로 제한 설정). 너무 많은 파일이있는 경우 파일 수가 한도 아래로 내려갈 때까지 파일을 개별적으로 삭제합니다. 당신은 파이썬 패키지 dropbox
을 설치해야합니다 (저는 Anaconda를 사용합니다, 그래서 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
@Flukey : 1GB 당 500MB. 그들은 꽤 작습니다. – Zach
나는 그것을 빨아 들이고 12 시간 동안 파일이 다른 컴퓨터에 다운로드 될 때까지 기다리는 것으로 해결했다. 그럼 내가 그들을 지웠고, 지금은 복숭아 같다. – Zach