Documents = ['*pdf', '*docx', '*txt']
for i in range(len(Documents)):
if glob.glob(Documents[i]):
print(Documents[i], True)
shutil.move(glob.glob(Documents[i])[0], '/home')
else:
print(Documents[i], False)
Well, everything goes great until:
shutil.move(glob.glob(Documents[i])[0], '/home')
Which is basically:
shutil.move(scr, dst)
And produces the error:
*pdf False
*docx True
Traceback (most recent call last):
File "/usr/lib/python3.2/shutil.py", line 326, in move
os.rename(src, real_dst)
OSError: [Errno 13] Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "teste.py", line 19, in <module>
shutil.move(glob.glob(Documents[i])[0], '/home')
File "/usr/lib/python3.2/shutil.py", line 334, in move
copy2(src, real_dst)
File "/usr/lib/python3.2/shutil.py", line 146, in copy2
copyfile(src, dst)
File "/usr/lib/python3.2/shutil.py", line 99, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/home/jesus.docx'
I tried using absolute path in both scr and dst and it didn't work. I browsed the web and found out that it might have something to do with permissions but if i have to change the permissions it will defeat the purpose of the script and that's why i will try to find help here before getting into the permissions thing.
So, what do i do?
My purpose is to move files in Linux user's directories. (sort them according to the file format..)...ex-> .jpg --> Pictures, .pdf --> Documents and so on. (That's why i can't be having permission thing hardening life...)
Also i'm a newbie at programming (just so you guys don't get very geeky :D ) And, this is also my first questions here at this community so please little patience if i sound lost or retundant? Thanks