Skip to content

Instantly share code, notes, and snippets.

@jrleeman
Created May 30, 2015 14:14
Show Gist options
  • Select an option

  • Save jrleeman/71ebcfe7060782fbbc14 to your computer and use it in GitHub Desktop.

Select an option

Save jrleeman/71ebcfe7060782fbbc14 to your computer and use it in GitHub Desktop.
Sorts acoustics records into folders to make management easier.
import os
import re
cwd = os.getcwd()
fnames = os.listdir(cwd)
# Find the log files
log_pattern = re.compile('^.*log.txt')
log_files = filter(log_pattern.search, fnames)
# Make a directory for each group of files
for group in log_files:
dname = group.split('log.txt')[0]
os.mkdir(dname)
# Move all files matching the search string into the corresponding directory
for group in log_files:
dname = group.split('log.txt')[0]
file_pattern = re.compile('^%s.*'%dname)
files_to_move = filter(file_pattern.search, fnames)
for file in files_to_move:
file_old_path = cwd + '/' + file
file_new_path = cwd + '/' + dname + '/' + file
print file_old_path, " --> ", file_new_path
os.rename(file_old_path,file_new_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment