#!/usr/bin/python

# print_case_insensitive_dupes.py
#       --copyright--                   Copyright 2020 (C) Tranzoa, Co. All rights reserved.    Warranty: You're free and on your own here. This code is not necessarily up-to-date or of public quality.
#       --url--                         http://www.tranzoa.net/tzpython/
#       --email--                       pycode is the name to send to. tranzoa.com is the place to send to.
#       --bodstamps--
#       October 23, 2020        bar
#       --eodstamps--
##      \file
#       \namespace              tzpython.print_case_insensitive_dupes
#
#
#       Print file names that collide on a Windows file system.
#
#

import  glob
import  os
import  sys
import  time

import  TZCommandLineAtFile


if  __name__ == '__main__' :
    argv    = sys.argv[1:]
    TZCommandLineAtFile.expand_at_sign_command_line_files(argv)

    retval  = 0

    fns     = {}
    for afn in argv :
        if  os.path.isdir(afn) :
            afn = os.path.join(afn, "*")

        for fn in glob.glob(afn) :
            bfn = os.path.basename(fn)
            ufn = bfn.upper()
            if  ufn in fns :
                fot = os.path.getmtime(fns[ufn])
                fnt = os.path.getmtime(fn)
                if  fot > fnt :
                    fno = fn
                    fnn = fns[ufn]
                    fot, fnt    = fnt, fot
                else    :
                    fno = fns[ufn]
                    fnn = fn
                print "----", time.asctime(time.localtime(fot)), fno
                print "    ", time.asctime(time.localtime(fnt)), fnn
                retval      = 1
            else :
                fns[ufn]    = fn
            pass
        pass
    sys.exit(retval)

#
#
#
# eof
