50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from pathlib import Path
|
|
import os
|
|
|
|
def get_all_sub_paths(path: Path):
|
|
if not path.exists() or not path.is_dir():
|
|
print(f"路径 {path} 无效或不是一个目录")
|
|
return
|
|
|
|
sub_path_list = []
|
|
|
|
for travel_dir_path in path.iterdir():
|
|
if travel_dir_path.is_dir():
|
|
sub_path_list.append(travel_dir_path)
|
|
for first_level_path in travel_dir_path.iterdir():
|
|
if first_level_path.is_dir():
|
|
sub_path_list.append(first_level_path)
|
|
for second_level_path in first_level_path.iterdir():
|
|
if second_level_path.is_dir():
|
|
sub_path_list.append(second_level_path)
|
|
print("second level dir")
|
|
return sub_path_list
|
|
|
|
def traverse_directory(paths):
|
|
for path in paths:
|
|
dir_name = str(path).replace("D:\\Photo\\", "")
|
|
network_path = Path(r"\\TRUENAS\Media\Photo\Photos") / dir_name
|
|
file_count_local = 0
|
|
file_count_network = 0
|
|
for sub_local in path.iterdir():
|
|
if sub_local.is_file():
|
|
file_count_local +=1
|
|
for sub_network in network_path.iterdir():
|
|
if sub_network.is_file():
|
|
file_count_network +=1
|
|
print(f"目录: {path.name}")
|
|
if file_count_local == file_count_network:
|
|
print(f"文件总数: {file_count_local}")
|
|
else:
|
|
print("!!!!!!!!文件数量不一致!!!!!!!!")
|
|
|
|
|
|
# path = Path('D:/') / 'Photo'
|
|
# path = Path('//TRUENAS') / 'Media' / 'Photo' / 'Photos'
|
|
path = r"\\TRUENAS\Media\Photo\Photos"
|
|
|
|
|
|
all_paths = get_all_sub_paths(Path(path))
|
|
# for path in all_paths:
|
|
# print(path)
|
|
traverse_directory(all_paths) |