Welcome, guest | Sign In | My Account | Store | Cart

Currently XnView image viewer (versions up to 1.97.6) correctly rotate images only when option "[x] make backup" set.

Backup files have added name part '.xnbak' before extension:

original file: IMG0001.jpg
backup file: IMG0001.xnbak.jpg

Attached script take a root directory in command line and remove backup files created by XnView only when rotated file present in same directory.

Python, 31 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import sys

__author__ = 'Denis Barmenkov <denis.barmenkov@gmail.com>'
__source__ = 'http://code.activestate.com/recipes/577281-xnview-backup-files-remove-utility/'

root_dn = sys.argv[1]

delete_files = list()

for root, dirs, files in os.walk(root_dn):
    for f in files:
        ii = f.split('.')
        if len(ii) > 2:
            prev_part = ii[-2].lower()
            last_part = ii[-1].lower()
            if last_part in ['jpg', 'jpeg'] and prev_part == 'xnbak':
                ii.pop(-2)
                rotated_name = '.'.join(ii)
                rotated_path = os.path.join(root, rotated_name)
                if os.path.isfile(rotated_path):
                    f_path = os.path.join(root, f)
                    # delete bak file
                    delete_files.append(f_path)

for f_path in delete_files:
    try:
        print f_path
        os.unlink(f_path)
    except OSError:
        print >>sys.stderr, 'ERROR DELETE: %s' % f_path