PlanB
Posts: 102
Joined: Tue Oct 28, 2014 6:44 am

shutil / listdir problem

Mon Jan 22, 2018 1:27 pm

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

User avatar
Paeryn
Posts: 2782
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: shutil / listdir problem

Mon Jan 22, 2018 3:22 pm

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.
She who travels light — forgot something.

PlanB
Posts: 102
Joined: Tue Oct 28, 2014 6:44 am

Re: shutil / listdir problem

Mon Jan 22, 2018 9:36 pm

Thnx, I shouldn't write code past my bedtime then embarrass myself online with dumb questions.

Return to “Troubleshooting”