"Rename" files across shares with Python (Solved)


Recommended Posts

I'm finally organizing my media properly with TV, Movies, and Music on their own shares. I made a little Python script that handles incoming files, sorting them into their appropriate folder; it worked great when everything was on one share. Not that everything is on different shares, my script has the same symptoms as Windows Explorer - even though files are moving around on the same disk, the file is copied then deleted, taking a bunch of extra time and wasted read/write cycles. Midnight Commander, running on the server, works exactly as expected. Is there any way to emulate this functionality through Python?

 

When everything was on the same share, os.rename() worked flawlessly, but now it throws an error about "different disk drives." I replaced it with shutil.move() but that does the whole copy nonsense. Is this because I'm running the Python script from Windows? If so, is there a way to run it through the server and would that fix the problem? The only Python environment I found was a PyCharm docker and that really wasn't a good solution, since the docker is sandboxed. Any help would be greatly appreciated. Thanks!

Edited by Crlaozwyn
Add Solved tag to title
Link to comment

Every OS in the world suffers the same "flaw".  Renames across mount points (shares) always does a copy / delete instead of a rename operation.  It's the proper way to do things, and is 100% correct, regardless if the files / shares are actually on the same drive or not.

Link to comment
2 hours ago, Squid said:

Every OS in the world suffers the same "flaw".  Renames across mount points (shares) always does a copy / delete instead of a rename operation.  It's the proper way to do things, and is 100% correct, regardless if the files / shares are actually on the same drive or not.

Thanks Squid. I appreciate the response. MC does not appear to copy/delete, as "moving" a 10GB file happens instantly. The issue, if it really was an issue at all, was that I was running the Python script from Windows, which didn't recognize the shares as being on the same drive. Once I ran the script on the server, it was instant again.

 

However, I've realized in testing that this behavior ignores split level settings for the share. I suppose my use-case is more complicated than I thought, because what I actually want is for it to move the pointer when the end point (EG season/artist) is on the same drive, but follow the split level settings to put it on the proper drive if different. Looks like I'll be writing some manual tests to determine start/endpoint drives and choose a command based on which outcome is needed.

Link to comment
2 hours ago, Crlaozwyn said:

MC does not appear to copy/delete, as "moving" a 10GB file happens instantly

Because the command line bypasses the entire system of mount points, since you're navigating on both to be /mnt/user/abc and /mnt/user/def so the mount point in both cases is /mnt/user

 

2 hours ago, Crlaozwyn said:

However, I've realized in testing that this behavior ignores split level settings for the share.

Along with included / excluded, useCache settings.  Because of the single mountpoint

Link to comment
2 hours ago, Squid said:

Because the command line bypasses the entire system of mount points, since you're navigating on both to be /mnt/user/abc and /mnt/user/def so the mount point in both cases is /mnt/user

 

Along with included / excluded, useCache settings.  Because of the single mountpoint

Thanks for the clarity - helps explain what I'm seeing. I'll do some more testing to see if the move command works as desired or if I need to emulate the functionality.

Link to comment
  • Crlaozwyn changed the title to "Rename" files across shares with Python (Solved)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.