python - shutil.move(scr, dst) gets me IOError: [Errno 13] Permission denied and 3 more errors -


documents = ['*pdf', '*docx', '*txt']  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, goes great until:

shutil.move(glob.glob(documents[i])[0], '/home') 

which basically:

shutil.move(scr, dst) 

and produces 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 above exception, 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     open(dst, 'wb') fdst: ioerror: [errno 13] permission denied: '/home/jesus.docx' 

i tried using absolute path in both scr , dst , didn't work. browsed web , found out might have permissions if have change permissions defeat purpose of script , that's why try find here before getting permissions thing.

so, do?

my purpose move files in linux user's directories. (sort them according file format..)...ex-> .jpg --> pictures, .pdf --> documents , on. (that's why can't having permission thing hardening life...)

also i'm newbie @ programming (just guys don't geeky :d ) and, first questions here @ community please little patience if sound lost or retundant? thanks

you're attempting write files /home directory. should not doing that.

linux multiuser operating system. /home of users home directories live. each user should have own directory under /home. example yours /home/joao.

change last parameter line

shutil.move(glob.glob(documents[i])[0], '/home') 

to

shutil.move(glob.glob(documents[i])[0], '/home/your_username') 

here's general improvement suggestion:

# variable names lower case documents = ["*.pdf", "*.docx", "*.txt"]  # iterate on loop this. python's for-each. actual item. doc in documents:      if glob.glob(doc):         shutil.move(glob.glob(doc)[0], '/home/your_username/documents') 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -