Quantcast
Channel: Python: detecting existing file : os.file.exists - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Python: detecting existing file : os.file.exists

$
0
0

I'm obviously doing something very wrong. I'd like to find files, that are in one directory but not in second directory (for instance xxx.phn in one directory and xxx.wav in second directory...

IT seems that I cannot detect, when file is NOT present in second directory (it's always showing like all files are)... I don't get any file displayed, although they exist...

import shutil, random, os, sysif len(sys.argv) < 4:    print """usage: python del_orphans_dir1_dir2.py source_folder source_ext dest_folder dest_ext"""    sys.exit(-1)folder = sys.argv[1]ext  = sys.argv[2]dest_folder = sys.argv[3]dest_ext  = sys.argv[4]i = 0for d, ds, fs in os.walk(folder):    for fname in fs:        basename = os.path.splitext(fname)[0]        if (not os.path.exists(dest_folder+'/'+basename +'.'+ dest_ext) ):            print str(i)+': No duplicate for: '+fname            i=i+1      print str(i)+' files found'

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images