tom meskin
tom meskin

Reputation: 5

problem with moving files with extensions with shutil

I have the following code that should move files from one directory to another, the problem is when I run the code it just creates the folder and not moving any file to it. can anyone help me with that?

import os
import glob
import shutil

def remove_ext(list_of_pathnames):

return [os.path.splitext(filename)[0] for filename in list_of_pathnames]

 path = os.getcwd()
 os.chdir("D:\\TomProject\\Images\\")   
 os.mkdir("image_with_xml")     # create a new folder
 newpath = os.path.join("D:\\TomProject\\Images\\" ,"image_with_xml") # 
 made it os 
 independent... 

 list_of_jpegs = glob.glob(path+"\\*.jpeg")
 list_of_xmls = glob.glob(path+"\\*.xml")

 jpegs_without_extension = remove_ext(list_of_jpegs)
 xmls_without_extension = remove_ext(list_of_xmls)

 for filename in jpegs_without_extension:
  if filename in xmls_without_extension:

 shutil.move(filename + '.jpg', newpath) # move image to new path.
 shutil.move(filename + '.xml', newpath)

Upvotes: 0

Views: 48

Answers (1)

kutschkem
kutschkem

Reputation: 8163

You first use ".jpeg" as extension but then when you move mistakenly use ".jpg".

Upvotes: 2

Related Questions