Skip to content

Instantly share code, notes, and snippets.

@pgampe
Last active February 14, 2017 15:07
Show Gist options
  • Save pgampe/c91a79f8eeecfd2a022122b7c0aaabb0 to your computer and use it in GitHub Desktop.
Save pgampe/c91a79f8eeecfd2a022122b7c0aaabb0 to your computer and use it in GitHub Desktop.
Migrate offlineimap separator from point to slash by moving all folders
import os
os.chdir('/path/to/your/local/copy/here')
dirs = os.listdir()
dirs.sort(key=len, reverse=True)
i = 0
for org_dir in dirs:
if '.' not in org_dir:
continue
new_dir = org_dir.replace('.', '/')
os.makedirs(new_dir, exist_ok=True)
parent_dir = os.path.dirname(new_dir)
if parent_dir == '':
continue
if not os.listdir(new_dir):
print('------------------')
print(org_dir)
print(new_dir)
print('------------------')
os.rename(org_dir, new_dir)
else:
print('------------------')
print(org_dir)
print(new_dir)
print('------------------')
dir_contents = os.listdir(org_dir)
for sub_dir in dir_contents:
old_sub_dir = org_dir + '/' + sub_dir
new_sub_dir = new_dir + '/' + sub_dir
print(old_sub_dir)
print(new_sub_dir)
os.rename(old_sub_dir, new_sub_dir)
print('====================')
os.rmdir(org_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment