i was trying to do this for a while and i cant find a way to do it. i need to search a string in my xml files that says 'drone' and than move all the files that contains the string to another directory
this is what im working with:
import os
import shutil
print("Contents of source and destination before moving:")
source = r"D:\\TomProject\\Images"
destination = r"D:\\TomProject\\txt"
for root, dir, files in os.walk(source):
print(root)
print(dir)
print(files)
print(os.listdir(destination))
for root, dir, files in os.walk(source):
for file in files:
if ".xml" in file: # checking if the file is a xml file by looking for .xml
extension in the name of the file
shutil.move(os.path.join(root, file), destination)
print("Contents of destination after moving:")
print(os.listdir(destination))