Hello,
I've got this directory with files that contain a number in their file name. I need to check what the number is and then I need to move the file to a different directory.
Right now I'm using shutil to do this, but for some reason it copies the file instead of moving it.
Here's a piece of my code:
import shutil, re, glob
checked_pages = glob.glob('C:/dir1/checked*.txt')
if checked_pages != []:
for file in checked_pages:
# Find out the file number
filepattern = re.compile(r'(checked)([0-9]+?)(.txt)')
if re.search(filepattern, file): # Is this necessary or can I leave the if-statement out?
found = re.search(filepattern, file)
filenumber = found.group(2)
else:
pass # Once again: is this necessary?
dest_file = 'C:/dir2/moved' + filenumber + '.txt'
shutil.move(file, dest_file)
# And here I'm gonna use the filenumber to do something else.
Does any of you have any idea why shutil doesn't remove the file from the source directory after copying it?
Thank you very much in advance!
Doris