Posted on

Using CMD to process files

It may be because I’ve been working side-by-side with engineers a lot recently, but I’ve been spending a good amount of time getting used to working in Windows CMD/Powershell.  For me, that’s meant pretty much never opening File Explorer and instead navigating around my system using one of the aforementioned two methods.

Powershell is neat of course because you can actually write custom scripts for repeat tasks, but I’ve even found the command line (CMD) to be a pretty big time saver.

So late last week I ran into this problem – I had about 1600 files to process in a DAW, which would leave me with 1600 duplicate files to eventually get rid of on my system.  The only difference (other than processing) between both sets is the converted set would have “_convt” at the end of its filename.

So how do you solve this without wasting a ton of time?  I could think of 3 immediate ways…

  1. Use File Explorer, manually click (or go a bit faster using the keyboard) to select each individual file and delete them.  This is fraught with human error and takes a lot of time – neither of which I could afford.
  2. Google for a program that can sort/delete files via a GUI.  I didn’t want to take the time to hunt for some dumb special program.
  3. Write a custom script to analyze the filenames, and delete the ones that didn’t include “_convt”.  I could do this, but I don’t know enough powershell scripting where it would take less time than option #1.

So what to do?

This is where CMD (you can do the same in Powershell) came in handy big time.

Since the Windows command line supports wildcards (*), you can actually feed it partial filenames in delete/copy/move commands!  This meant that instead of finding the files that didn’t include “_convt”, I just had to find something unique about the other files to tell the command line to look for.

Let me explain with an example:

My file list looked something like this, repeating —

  • File1_Intro.wav
  • File1_Win.wav
  • File1_Lose.wav
  • File1_Intro_convt.wav
  • File1_Win_convt.wav
  • File1_Lose_convt.wav

So you see I wanted to keep the “_convt” files, but delete the others.  Additionally, each file had “_Intro”, “_Win”, or “_Lose” as unique identifiers in their filenames.

So within CMD it’s as easy as using these commands:

  • del *_Intro.wav
  • del *_Win.wav
  • del *_Lose.wav

In this case the wildcard (*) character means that the specific text before “_Intro”, “_Win”, or “_Lose” doesn’t matter.  So long as the filename has one of those suffixes with “.wav” immediately after, it would be deleted.

Note how that immediately leaves me with only files that have “_convt” as their filename suffix.  Now with any number of mass rename tools, I easily removed the last 6 characters of the filename and I was done!

Pretty cool huh?  Sometimes it pays to get used to ways of working that initially seem difficult.

Copyright 2016-2017, Adam T. Croft, all rights reserved.