Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created October 20, 2011 03:56
Show Gist options
  • Save mark-cooper/1300380 to your computer and use it in GitHub Desktop.
Save mark-cooper/1300380 to your computer and use it in GitHub Desktop.
Count occurrences of file basenames from a single folder and select those that appear once ...
from os import listdir
from os.path import basename, isfile, join, splitext
src_dir = 'c:\\repository\\'
files = {}
for file in listdir(src_dir):
src_file = join(src_dir, file)
if isfile(src_file):
base = splitext(basename(src_file))[0]
if base in files:
files[base] += 1
else:
files[base] = 1
unique = [file for file in files.keys() if files[file] == 1]
print unique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment