Skip to content

Instantly share code, notes, and snippets.

@jeffgerhard
Created August 10, 2016 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffgerhard/72eda81f1adfeccde70ae8ad51a29fb2 to your computer and use it in GitHub Desktop.
Save jeffgerhard/72eda81f1adfeccde70ae8ad51a29fb2 to your computer and use it in GitHub Desktop.
# cleans up the downloaded, bagged masters
# and moves to archival storage
#
# could combine this with the IA download script?
#
# leaves behind a log file with the id's to plug them into the Access db
import os
import shutil
from tkinter.filedialog import askdirectory
#from tkinter import messagebox
#from sys import exit
#from shutil import rmtree
def get_subdirectories(a_dir):
# stackoverflow.com/questions/800197/how-to-get-all-of-the-immediate-subdirectories-in-python#800201
return [name for name in os.listdir(a_dir)
if os.path.isdir(os.path.join(a_dir, name))]
dirname = askdirectory(title='directory to move', initialdir='Z:\\holding\\books\\IA_download\\')
m_dir='Z:\\archival_master_files\\books\\general_collection\\'
dirlist = get_subdirectories(dirname)
warningslist = []
logname = os.path.join(dirname, "log.txt")
for d in dirlist:
with open(logname, 'a') as fh:
fh.write(d[:-7] + '\n')
localdir = os.path.join(dirname, d)
dest = os.path.join(m_dir, d)
shutil.move(localdir,dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment