-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_XML_image.py
More file actions
29 lines (23 loc) · 1.18 KB
/
split_XML_image.py
File metadata and controls
29 lines (23 loc) · 1.18 KB
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
import os
import shutil
# Source directory containing both image and XML files
source_directory = './datasets/test'
# Destination directories for images and XML files
images_destination = './datasets/images'
xml_destination = './datasets/annots'
# Ensure the destination directories exist
os.makedirs(images_destination, exist_ok=True)
os.makedirs(xml_destination, exist_ok=True)
# Loop through the files in the source directory
for filename in os.listdir(source_directory):
source_file = os.path.join(source_directory, filename)
# Check if the file is an image (you can modify the condition based on your file naming conventions)
if filename.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.bmp')):
# If it's an image, move it to the images destination directory
destination_file = os.path.join(images_destination, filename)
shutil.move(source_file, destination_file)
elif filename.lower().endswith('.xml'):
# If it's an XML file, move it to the XML destination directory
destination_file = os.path.join(xml_destination, filename)
shutil.move(source_file, destination_file)
print("Files have been split into images and XML folders.")