Spring Cleaning With CMD and Excel
May 13, 2019, 11:21 p.m.
While abstractly I understood programming is a powerful tool to work with the world, it still sometimes felt magical and just beyond the optimal level of layman's terms that made it click. Even after taking Udemy courses and reading books, the examples were too trivial. Here comes ANOTHER for loop, or another Hello XYZ template to demonstrate a 123 switch case. It seemed like one giant conspiracy where every publisher and trainer was using the same examples, just packaged into the syntax of the specific language.
There's only so much "Hello Worlding" a person can go through. Sailing in Nintendo is all well and good, but if you're not feeling the waves, if your adrenaline is not pumping at looming thunderclouds, if you're not smelling the seawater, it's simply not the same.
After I finish this Udemy course, I can sail the Seven Seas!
I'd find more use in a cheat sheet comparing the syntax from a list of languages. This would prove more beneficial than bloated, repetitive resources that give little sense of movement.
While reading about portfolios and how to code personally interesting projects, I found the advice uninspiring. I started to think the problem was me. I'm looking for advice for a non-existent problem. I just didn't have a burning desire to do anything at that moment. I was comfortable doing things the way I wanted. And that's not very good with coming up for portfolio ideas or solutions I'd be passionate and motivated enough about to stick through.
My goal in this post is not to complain. It's to demonstrate how theory, practice and pedagogy can be improved with a targeted change in perspective. There's a quick limit to theoretical demonstration and "do what you want" motivation.
When programming is thought of as a method to make your life more efficient on a down-to-earth level, then the desire to find the solution becomes all-encompassing. Suddenly doubts and lack of knowledge take a back-seat to trying to acheive the exact result. Hours spent hacking away at lines of code feel like minutes (when it's not some frustrating bug) because the flow and joy of working at a resolution feels intrinsically satisfying.
One day I decided I needed to organize all my files, folders, pictures and videos. I had a digital mess the equivilant of Beethoven's organization of his sketches.
Waldo wasn't even here. He was on the other hard drive.
Suddenly moving the mouse and copy pasta would not cut it. I had to rename hundreds of files with specific labels I had in mind in addition to moving them to their correct locations while preventing duplicate files from remaining. Copy pasta would have taken forever as everything was so scattered about.
My mind suddenly shifted gears. No more tutorials or books or examples. The task in front of me was to use my programming knowledge to clean up my digital closet accurately and quickly, seeing real results right in front of me. To be a happy customer and have everything the way I ordered it. I didn't need to slog through contrived problems I had little interest in solving for the sake of them.
I didn't know much about bash or powershell, and I wasn't in the mood to sit through another four hours of for loops. So I started to do what apparently many programmers do: go directly to the source by consulting relevant documentation. Now I don't know if the pros do this but after bashing my digi-head against the shell until things started to click, I saw the fruits grow.
It helped that I had a specific outcome in mind to help focus on how I wanted the output. In this case I wouldn't take no for an answer, since I knew I could get the result manually with enough clicks and time. Knowing this gave me the confidence to seek out the automated solution.
Looking back on it now, the solution itself wasn't complex at all. Sure it required proper syntax and switch flag tweaking in the command line, but in the grand scheme of things, neither you nor I would need a 20 hour course to get things like this done. A little bit of focused document reading and a lot of willpower can take one far.
First I needed to generate a list of all files derived from various root directories recursively. Once I had them, I'd load them into excel and massage the data so filenames and locations were separate and any extraneous information on the edge columns. Then I'd flag any duplicates and choose what was kept.
This cmd line would move all flagged duplicates to a central folder for final review and deletion.
="move " & """" & B1 & "\" & A1 & """" & " " & """C:\delete"""I'd use similar commands to sort all travel photos by date and move all within certain date ranges to their respective trip folders. Once everything is properly flagged in excel, I'd copy the formulas into a .BAT file, run it in cmd and watch the magic happen. A transwarp of garbage and treasure land in their proper folders.
Checking the different switch flags helped me customize the code to my situation. In this case to get a list of all files recursively I'd type the following:
dir /s /b "C:\dir" > list_of_files.txtSome files appeared in the duplicate folder but were actually unique. So I moved them back in bulk to a safe folder:
for %i in (list of files separated by comma ID'ed as safe in excel) do copy %i "C:\safe\dir\to\keep\files"What cleaning my digital room taught me is a programmer's job is to bring order out of chaos. What looks like a daunting situation can easily be transformed into a pleasant atmosphere and requires much less work than initially believed.
The hardest part is coming up with a plan, mapping out the details needed and then going through with implementation. Small steps ensure you're going in the right direction, and it's better to have small bumps than massive turbulence. Thus testing continuously helps mitigate errors along the way.
The best part was I accomplished my task not in neither a complex nor trendy language, but with simple Windows command line tinkering. And this was the biggest lesson I learned. The language itself is trivial. What matters is the results you want, and the way you plan on transforming your data into the desired output. From the punch-card system of the 70s, to the latest JavaScript library or OOP language, this is what programmers are trying to do, and now I felt deeper in that circle. Not to mention that my file organization was better accessible while my hard-drive space shed a few GB of bloat.