Skip to content

Instantly share code, notes, and snippets.

@hvgab
Created January 6, 2020 01:10
Show Gist options
  • Save hvgab/d932b44bfb17569f3873404d65e35c52 to your computer and use it in GitHub Desktop.
Save hvgab/d932b44bfb17569f3873404d65e35c52 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
"""
04.12.2015
Based on "tag" in filename, move file into directory named with the same tag.
"""
import sys, os, time, shutil, re
path = './' #this folder
files = os.listdir(path) # make a list of all files in this dir
files.sort()
counter = 0
magazines = ['ATR', 'BOB', 'BOL', 'COS']
def checkAndMove(f, path, magazine_code):
reg = re.compile('_'+magazine_code+'_')
if (reg.search(f)):
shutil.move(path + f, path + magazine_code + '/' + f)
global counter
counter += 1
print (f + ' moved to ' + magazine_code)
for f in files:
for mag in magazines:
checkAndMove(f, path, mag)
print ("Moved files:")
print (counter)
input("Press Enter to continue...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment