-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_processing.py
53 lines (40 loc) · 1.69 KB
/
data_processing.py
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
42
43
44
45
46
47
48
49
50
51
52
53
import os
def delete_xml_files(folder_path):
try:
# 获取文件夹中所有文件和子文件夹的列表
files_and_folders = os.listdir(folder_path)
# 遍历每个文件或子文件夹
for item in files_and_folders:
item_path = os.path.join(folder_path, item)
# 如果是文件夹,递归调用 delete_xml_files
if os.path.isdir(item_path):
delete_xml_files(item_path)
# 如果是.xml文件,删除
elif item.lower().endswith('.xml'):
os.remove(item_path)
print(f"Deleted: {item_path}")
except Exception as e:
print(f"An error occurred: {e}")
def count_png_files(folder_path):
try:
# 获取文件夹中所有文件和子文件夹的列表
files_and_folders = os.listdir(folder_path)
# 初始化计数器
png_count = 0
# 遍历每个文件或子文件夹
for item in files_and_folders:
item_path = os.path.join(folder_path, item)
# 如果是文件夹,递归调用 count_png_files
if os.path.isdir(item_path):
png_count += count_png_files(item_path)
# 如果是.png文件,增加计数器
elif item.lower().endswith('.png'):
png_count += 1
return png_count
except Exception as e:
print(f"An error occurred: {e}")
return 0
# 使用示例
folder_path = 'D:\\Infrared small object detection\\record\\code-set\\IEEE_TIP_UIU-Net\\masks'
total_png_files = count_png_files(folder_path)
print(f"Total number of .png files: {total_png_files}")