Created
May 30, 2015 14:14
-
-
Save jrleeman/71ebcfe7060782fbbc14 to your computer and use it in GitHub Desktop.
Sorts acoustics records into folders to make management easier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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