2017-10-11 19 views
-1

2つのフォルダの高さと高さがあります。 Highresフォルダには約20個のフォルダがあり、300個の画像が含まれています。私はhighresイメージを小さく変換し、lowresフォルダにコピーします。今、私はhighresから欠落した画像をPATHが言及されたlowresフォルダと比較したいと思います。 PythonとWindowsで必要です。pythonのパスとフォルダとの内容を比較する

import os 
    def get_files(basedir): 
     for names, dirs, files in os.walk(basedir): 
      for file in files: 
       path = os.path.join(names, file) 
       yield path [len (basedir)+1:1] 
    highres = set(get_files('D:/compare/highres')) 
    lowres = set(get_files('D:/compare/lowres')) 

    diff_lowres = highres-lowres 
    diff_highres = lowres-highres 
    print 'Copy to lowres folder :\n' diff_lowres 
    print 'Remove extra images from LowRes folder :\n' diff_highres 
+0

あなたが試してみたコードを投稿してください。 – quamrana

+0

あなたは何を持っているのですか?あなたの 'set'にはあなたが期待するデータなどが入っていますか? –

+0

質問中にコードをコピーして貼り付けるのを忘れました。今すぐチェックしてください – Murali

答えて

0
import os 
def get_files(path): 

    myFiles = [] 

    #files = os.listdir (path) 
    for names, dirs, files in os.walk(path):    
     for eachFile in files :    
      if os.path.isfile(os.path.join(names, eachFile)) :      
       filePath = os.path.abspath(os.path.join(names, eachFile)).replace ('\\', '/')      
       finalPath = filePath.replace (path, '')                 
       myFiles.append (finalPath)  

    return myFiles  

loRespath = 'C:/Users/***********/SourceImages/LoRes' 
hiRespath = 'C:/Users/***********/SourceImages/HiRes' 

lowres = get_files(loRespath) 
highres = get_files(hiRespath) 

diff_lowres = [] 
diff_highres =[] 

for eachLower in lowres :  
    if eachLower not in highres : 
     diff_lowres.append (eachLower) 

for eachHighres in highres :  
    if eachHighres not in lowres : 
     diff_highres.append (eachLower)   
+0

これはうまくいった。どうもありがとう。 – Murali

0
import os 

def get_files(path): 

    myFiles = [] 
    files = os.listdir (path)   
    for eachFile in files :   
     if os.path.isfile(os.path.join(path, eachFile)) : 
      myFiles.append (eachFile)   
    return myFiles  

highres = get_files('D:/compare/highres') 
lowres = get_files('D:/compare/lowres') 

diff_lowres = [] 
diff_highres =[] 

for eachLower in lowres :  
    if eachLower not in highres : 
     diff_lowres.append (eachLower) 

for eachHighres in highres :  
    if eachHighres not in lowres : 
     diff_highres.append (eachLower)   

print diff_lowres 
print diff_highres   
+0

ありがとうSubin。このスクリプトは、絶対パスのみで動作しています。サブフォルダをチェックインし、パスも印刷する必要があります。 – Murali

関連する問題