The Great Cow Frame Mover

Last night I decided to start putting together the script that will do the real work of moving all my frames into their respective folders. I had to jump slightly ahead of where I was in Automate the Boring Stuff, but not by much. At this point I’m starting to pick things up a little faster.

By this afternoon, with some repeated failures that turned out to be a case of Windows Explorer not updating fast enough, I had a script that sorted and moved files from one central folder into a bunch of separate folders. It turned out surprisingly simple, and while it still needs to be setup to operate on user input rather than hard-coded directories, the functionality is what I figured it should be.

But, as with most things, I wasn’t happy with that. As you can see by my big #TODO note, I wanted the user feedback to be a little cleaner. Instead of printing something on on every single frame it was moving, I only wanted it to print each shot once. After it finished one shot’s frames and moved onto the next, print the next one. That way we know the script is running but it’s not this insane machine gun effect of essentially the same line over and over.

As you may also note, I sort of worked out the logic of what I should be doing instead, and immediately set off to create that. This initial version was looking at the folder full of EXR files and then iterating over every single one of them, using a regular expression to extract the shot name and then move it to where it needed to go. This meant printing any sort of feedback would happen on every single frame. It also meant running a chunk of code on every single frame.

Inverting My Approach

I figured if I only wanted something printed out when the shot number changed, then the easiest way would be to iterate through a list where the shots only appear once. So I flipped everything on its head and used the VFX directory as my list. I then used the glob module to find all files that contain the folder’s name, which itself returns a list of matches. I could then just iterate through that list and move those frames to where they need to go. So just one line of code being repeated the most, rather than four.

My initial test of this didn’t work quite right. My test folder has all 116 folders created for Brothers’ Quarrel, but I’m only testing on a few shots. So what happened was the first few shots gradually spit out "Moving [shot] to [directory],” but then it rapidly spit the same line out for all the rest of the shots. I had forgotten that I’m iterating through the entire shot list, with no regard for whether or not frames exist for them. Hence my little conditional checking if the frames list contains anything. If the glob module checks for a shot name that doesn’t exist in the files it’s looking at, then it’ll return an empty list. It’s length will be 0, which is false, and the line won’t be printed. It amuses me how often programming is about preventing something from happening.

Much cleaner.

My task for the rest of the night is to set this up to run in the command line and take some user input, so the file paths can change. For now I’ll let it assume my file hierarchy, because I’m the only one using these scripts. But I am thinking about making things more open ended in case anyone wants to fiddle with them. None of this is even on GitHub at the moment anyway.


7/18/20 Edit: I realized as I climbed into bed last night that I forgot to actually time the two scripts. My assumption that the second way would be more efficient turned out to be correct. While iterating through every frame in the source folder and executing a block of code each time, moving 550 or so files took 14.13 seconds. Running the updated script, which I updated further to only execute the move when the glob returns a list, the same set of files were moved in 11.05 seconds.

Previous
Previous

Boris FX - Why I ❤️ Silhouette

Next
Next

First, Let Me Build a System