Skip to content

Instantly share code, notes, and snippets.

@blucksy
Created April 25, 2020 21:57
Show Gist options
  • Select an option

  • Save blucksy/cf3a8ae377505724480ed15cec29e71a to your computer and use it in GitHub Desktop.

Select an option

Save blucksy/cf3a8ae377505724480ed15cec29e71a to your computer and use it in GitHub Desktop.
script to take year from pdfs and organize them (wire issue archives)
import os
import shutil
if __name__ == "__main__":
def numOnly(x):
res = [int(i) for i in x.split() if i.isdigit()]
return res
files = [f for f in os.listdir('.') if os.path.isfile(f)]
folders = [f for f in os.listdir('.') if os.path.isdir(f)]
destFolder = ['1980-1990','1990-2000','2000-2010','2010-2020','else']
for folder in destFolder:
os.mkdir(folder)
for f in files:
year = numOnly(str(f))
print(year)
try:
#if 1980-1990
if year[0] in range(1979, 1991):
print('1980-1990')
shutil.move(os.getcwd() + '\\'+f, os.getcwd() + '\\1980-1990')
#if 1990-2000
if year[0] in range(1991, 2001):
print('1990-2000')
shutil.move(os.getcwd() + '\\'+f, os.getcwd() + '\\1990-2000')
#if 2000-2010
if year[0] in range(2001, 2011):
print('2000-2010')
shutil.move(os.getcwd() + '\\'+f, os.getcwd() + '\\2000-2010')
#if 2010-2020
if year[0] in range(2011, 2021):
print('2000-2010')
shutil.move(os.getcwd() + '\\'+f, os.getcwd() + '\\2010-2020')
else:
shutil.move(os.getcwd() + '\\'+f, os.getcwd() + '\\else')
except:
pass
@blucksy
Copy link
Copy Markdown
Author

blucksy commented Nov 23, 2021

Looking back on this it could def use some abstraction lol...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment