Page 1 of 1

shutil / listdir problem

Posted: Mon Jan 22, 2018 1:27 pm
by PlanB
I've got a simple little python 2.7 program (running under Jessie) for moving a photo;
photo_queue = listdir('/home/pi/photos')
shutil.move('photo1.png', '/home/pi/photos/photo1.png')
print str(photo_queue)

To my great surprise the last line didn't produce any output! But if I move the print to a separate program & run it the photo I moved with shutil shows up. It's like shutil has locked the file or something & only releases it after the first program has terminated. Anybody got some clues? I tried a time.sleep(60) before the print but no joy, the print has to be in a separate program

Re: shutil / listdir problem

Posted: Mon Jan 22, 2018 3:22 pm
by Paeryn
Your program first gets a list of the contents of the directory /home/pi/photos, then moves photo1.png into that directory and then prints the list it got before the move. There's no surprise that the file moved after the list was created doesn't appear in the list.

Re: shutil / listdir problem

Posted: Mon Jan 22, 2018 9:36 pm
by PlanB
Thnx, I shouldn't write code past my bedtime then embarrass myself online with dumb questions.