File size: 1,382 Bytes
58102e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
import os
import sys
import shutil

def get_subdirectories(dir_path):
    return [d for d in os.listdir(dir_path) if os.path.isdir(os.path.join(dir_path, d))]

def main(dir1, dir2):
    base_dir = "./must-bench"
    dir1_path = os.path.join(base_dir, dir1)
    dir2_path = os.path.join(base_dir, dir2)
    
    subdirs1 = set(get_subdirectories(dir1_path))
    subdirs2 = set(get_subdirectories(dir2_path))
    common_subdirs = subdirs1.intersection(subdirs2)
    
    new_dir = base_dir + '/' + dir1 + '-' + dir2
    if not os.path.exists(new_dir):
        os.makedirs(new_dir)
    
    for subdir in common_subdirs:
        dir1_sub_path = os.path.join(dir1_path, subdir)
        dir2_sub_path = os.path.join(dir2_path, subdir)
        dst_path = os.path.join(new_dir, subdir)
        os.makedirs(dst_path, exist_ok=True)
        
        total_files = os.listdir(dir1_sub_path) + os.listdir(dir2_sub_path)
        
        for file in total_files:
            file1 = os.path.join(dir1_sub_path, file)
            file2 = os.path.join(dir2_sub_path, file)
            
            if os.path.exists(file1):
                
                shutil.copy(file1, os.path.join(dst_path, f"{dir1}_{file}"))
            if os.path.exists(file2):
                shutil.copy(file2, os.path.join(dst_path, f"{dir2}_{file}"))

if __name__ == "__main__":
    main(sys.argv[1], sys.argv[2])