Skip to content

Instantly share code, notes, and snippets.

@akaihola
Created November 10, 2013 09:26

Revisions

  1. akaihola created this gist Nov 10, 2013.
    40 changes: 40 additions & 0 deletions movephotos.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/python3.3

    import os


    NEWDIR = '/home/akaihol/Kuvat_'
    OLDDIR = '/media/akaihol/tasku/Valokuvat'


    def get_file_fingerprint(path):
    return os.path.getsize(path), os.path.basename(path)


    def scan_paths(root_directory):
    new_paths = {}
    for root, _dirs, files in os.walk(root_directory):
    for filename in files:
    absolute_path = os.path.join(root, filename)
    fingerprint = get_file_fingerprint(absolute_path)
    relative_path = os.path.relpath(absolute_path, root_directory)
    if not relative_path.startswith('.git/'):
    new_paths[fingerprint] = relative_path
    print(relative_path)
    return new_paths


    def move_to_new_path(from_path, to_path):
    print('git mv', from_path, to_path)


    def main():
    new_paths = scan_paths(NEWDIR)
    old_paths = scan_paths(OLDDIR)
    for fingerprint, path in old_paths.items():
    if fingerprint in new_paths and new_paths[fingerprint] != path:
    move_to_new_path(path, new_paths[fingerprint])


    if __name__ == '__main__':
    main()