Skip to content

Instantly share code, notes, and snippets.

@blakerohde
Created August 22, 2013 03:40
Show Gist options
  • Save blakerohde/6302980 to your computer and use it in GitHub Desktop.
Save blakerohde/6302980 to your computer and use it in GitHub Desktop.
Used to search a starting directory recursively looking for files with seafile conflict strings in their filename.
#!/usr/bin/env python
"""
seafile-conflict-detector.py
Used to search a starting directory recursively looking for files with seafile conflict strings in their filename.
:copyright: (c) 2013 by Blake Rohde.
:license: ISC, see LICENSE for more details.
"""
import fnmatch, os, argparse, sys
# Edit "[email protected]" to be your seafile user email address
ex_conf_msg_pre = ' ([email protected] '
ex_conf_msg = ex_conf_msg_pre + 'YYYY-MM-DD-HH-MM-SS)'
ex_conf_msg_len = len(ex_conf_msg)
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('start_dir', default='',
help='the directory to being recursively searching and replacing the search string')
parser.add_argument('log_filename', default='',
help='the filename for the log of file renames to be logged')
parser.add_argument('--search_string', default='*' + ex_conf_msg_pre + '*',
help='the search string to remove/replace')
parser.add_argument('-s', '--simulate', action='store_true', default=False,
help='do not actually rename the files')
args = parser.parse_args(args=argv)
log = open(args.log_filename, 'a+')
for root, dirnames, filenames in os.walk(args.start_dir):
for filename in fnmatch.filter(filenames, args.search_string):
path = os.path.join(root, filename)
fname, ext = os.path.splitext(path)
if ext == '':
log.write(path + os.linesep)
#if args.simulate == False:
#os.rename(path, path[:-ex_conf_msg_len])
else:
log.write(path + os.linesep)
#if args.simulate == False:
#os.rename(path, fname[:-ex_conf_msg_len] + ext)
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment