Reputation: 1687
Hi Trying to move logs that are finished being processed but I think I'm using shutil wrong.
import shutil
path = '/logs/'
finDir = '/complete/'
# parse loop
def getUniquePath(path):
for filename in os.listdir(path):
if..processing log
shutil.move(filename, finDir) #moves completed files
I keep getting errors that file does not exist.
So I added a print statement after the loop and it correctly prints out the filename and the destination so I'm thinking that I am just using shutil.move incorrectly.
Thanks
Upvotes: 2
Views: 1551
Reputation: 368944
You need to combine path
with filename
unless you are in the /logs/
directory.
Otherwise, file searching is done in the current directory; which cause file not found, or wrong file manipulation (if there was the file with the same name in the current directory)
Using os.path.join
:
import os
import shutil
path = '/logs/'
finDir = '/complete/'
# parse loop
def getUniquePath(path):
for filename in os.listdir(path):
..
shutil.move(os.path.join(path, filename), finDir)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Upvotes: 1