Note that there are some explanatory texts on larger screens.

plurals
  1. POErrno 22 with Python shutil and .move() function
    primarykey
    data
    text
    <p>Alright, so I've been debugging this for most of the afternoon and I'm throwing in the towel.</p> <p>I'm trying to create a system that will help automate putting work folders back on the server after my student workers are done with them. I've gotten everything down so far--it correctly identifies the matching server folder, and it is able to move the server folder into an Archive folder to temporarily back it up while I copy the new work back.</p> <p>However, it's that last bit that's holding me up. Everything is working beautifully, until I get to the part where I copy the folder that's passed as an argument back onto the server.</p> <p>Here is the problem piece of code:</p> <pre><code>print "Match Source: " + match_src archive_folder_name = match_src.rsplit('/', 1)[1] print "Archive Folder Name: " + archive_folder_name if not (os.path.isdir(os.path.join(os.path.dirname(match_src), "Archive"))): os.mkdir(os.path.join(os.path.dirname(match_src), "Archive")) archive_dst = os.path.join(os.path.join(os.path.dirname(match_src), "Archive"), archive_folder_name) print "Archived Folder Destination: " + archive_dst # okay, archive folder has been made. Now we need to move the old # stuff to this folder. shutil.move(match_src, archive_dst) # okay, archive folder is filled. Now to move the new stuff there print "Updated Source: " + updated_folder_path print "Destination: " + os.path.dirname(match_src) shutil.move(updated_folder_path, os.path.dirname(match_src)) </code></pre> <p>And here is the output from those print statements, and the error code:</p> <pre><code>ServerReturn mwl36$ python serverreturn_main.py /Users/mwl36/Desktop/Week\ 1 I'm on a Mac. Path: /Users/mwl36/Desktop/Week 1 Folder: Week 1 Match Source: /Volumes/GCPSX Mac HD/ID/Marisa/Work for Student Workers/201315/SERVERTEST/Week 1 Archive Folder Name: Week 1 Archived Folder Destination: /Volumes/GCPSX Mac HD/ID/Marisa/Work for Student Workers/201315/SERVERTEST/Archive/Week 1 Updated Source: /Users/mwl36/Desktop/Week 1 Destination: /Volumes/GCPSX Mac HD/ID/Marisa/Work for Student Workers/201315/SERVERTEST Traceback (most recent call last): File "serverreturn_main.py", line 124, in &lt;module&gt; main() File "serverreturn_main.py", line 117, in main shutil.move(updated_folder_path, os.path.dirname(match_src)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 296, in move copytree(src, real_dst, symlinks=True) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 206, in copytree raise Error, errors shutil.Error: [('/Users/mwl36/Desktop/Week 1/testfile.txt', '/Volumes/GCPSX Mac HD/ID/Marisa/Work for Student Workers/201315/SERVERTEST/Week 1/testfile.txt', "[Errno 22] Invalid argument: '/Volumes/GCPSX Mac HD/ID/Marisa/Work for Student Workers/201315/SERVERTEST/Week 1/testfile.txt'")] </code></pre> <p>Where am I going wrong? If the call to do shutil.move(src, dst) worked the first time without issues, why is it barfing here? I've tried adding in a delay after the initial call, to no effect.</p> <p>EDIT: What's even stranger is that it will actually perform the move, but never seems to delete the old folder on the desktop. Essentially, it copies the folder to the DST location, but doesn't clean up after itself.</p> <p>EDIT #2: Calling os.listdir shows that the directory is gone, and that the only thing in there prior to the second move call is 'Archive'. I will test out copy() tomorrow when I'm at work and have access to the code again.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload