Mass File Rename

Posted by: tanstaafl.

Mass File Rename - 01/11/2017 20:19

I have more than 900 files named in the format Raw Data ###.png and when I pass file Raw Data 999.png, the next one will of course be Raw Data 1000, then 1001 etc. This is going to cause some alphabetizing problems, not in the Windows directory tree, but in my Excel spreadsheet where part of the filename must be stored as part of a text cell and is used as a sort key.

Is there a quick and easy way to add a zero ahead of the "###" part of my 900+ filenames in Windows, changing the name from, for example, "Raw Data 092" to "Raw Data 0092" for all the files? I can deal with the changes in Excel with a couple of search-and-replace runs, but I don't have that option with the Windows directory tree.

For perspective, I can create a macro in my programmable keyboard that will allow me to change each individual file with a single keystroke, so if the solution is more complex than repetitively pressing a designated key 925 times I'll probably just do that.

tanstaafl.
Posted by: jmwking

Re: Mass File Rename - 02/11/2017 01:03

I found and tweaked this some time ago for similar stuff that I only do rarely. It's not pretty, but it works for me - but only with pictures with the same number of digits at the end, and all going to the same beginning. So if you have "raw data nnn" and want "raw data 0nnn" you can only work with photos with 3 digits: move those to your "working" folder, run the batch file, then move them back.

Note: it won't work if you have different beginnings of filenames. I imagine someone can capture the initial part and reinsert it - this board is awesome that way! - but I don't do that. All my main camera's photos get JKn_xxxx treatment, with the n iterating. (I'm no longer team photographer for two kids, so I'm taking many fewer pics. But if I ever get to JK9_ I'll be in a similarly sinking boat...)

-jk


Code:
@echo off
setlocal enableextensions enabledelayedexpansion
rem iterate over all jpg files:
for %%f in (*.jpg) do (
    rem store file name without extension
    set FileName=%%~nf
    rem Trim to only x digits, from the end (just replace numeral for the number of digits at end of photo)
    set FileName=!FileName:~-4!
    rem Add "JK4_" and extension again (I replace the headers with JKn_; add JKn_0 to pad)
    set FileName=JK4_!FileName!%%~xf
    rem Rename the file
    rename "%%f" "!FileName!"
)
Posted by: Dignan

Re: Mass File Rename - 03/11/2017 01:50

I used to use a fantastic application called "The Rename" that was fairly intuitive and fairly well designed. But it looks like it's no longer developed and isn't supported under Windows 10, and can only be found on sites like Softpedia which I rarely trust.

I've used this other program called Bulk Rename Utility. It has a ton of options but it's hard to figure out. Whenever I do a bulk rename, I ALWAYS do it to a copied folder of the files I'm working on. Never the original.
Posted by: tanstaafl.

Re: Mass File Rename - 03/11/2017 03:12

I'll probably just use a keyboard macro to rename the files one at a time. One keystroke per file won't kill me.

Something like:

F2 Home Ctrl-Right-Arrow Ctrl-Right-Arrow 0 Enter Down-Arrow

and repeat about 900 times.

tanstaafl.
Posted by: tahir

Re: Mass File Rename - 03/11/2017 11:12

Originally Posted By: Dignan
I used to use a fantastic applications called "The Rename" that was fairly intuitive and fairly well designed. But it looks like it's no longer developed and isn't supported under Windows 10, and can only be found on sites like Softpedia which I rarely trust.

I've used this other program called Bulk Rename Utility. It has a ton of options but it's hard to figure out. Whenever I do a bulk rename, I ALWAYS do it to a copied folder of the files I'm working on. Never the original.


Likewise, BRU is a lot less intuitive than the Rename but it does just about anything.
Posted by: mlord

Re: Mass File Rename - 03/11/2017 13:39

Code:
#!/bin/bash
function rename_png(){
        while read raw data n ; do
                old="$raw $data $n"
                new="$raw $data $(printf '%04u' ${n%%.png}).png"
                [ "$old" = "$new" ] || mv -v "$old" "$new"
        done
}
/bin/ls -1 Raw\ Data\ [0-9][0-9]*.png | rename_png


That can probably be done simpler, but there it is after two minutes of typing.
Posted by: JBjorgen

Re: Mass File Rename - 03/11/2017 15:13

That's what I was thinking too, Mark, but I think the chances of Doug installing a bash environment in windows to do a bash script are almost nil. Not sure if something similar is possible with a batch file?
Posted by: tanstaafl.

Re: Mass File Rename - 03/11/2017 16:41

Originally Posted By: JBjorgen
I think the chances of Doug installing a bash environment in windows to do a bash script are almost nil.
Surely you aren't implying that I might be less technically competent than you or Mark? Oh, wait... smile smile

By my calculations, doing the job with the keyboard macro will take me five minutes and 15 seconds, plus an additional 20 seconds to install the macro. Almost certainly less time consuming and much safer than other alternatives!

* * * * *

Okay, the job is done, but it took longer than anticipated. Instead of 5:15, it was 5:50, but I cut almost 10 seconds off the time it took to create the keyboard macro to make up some of the overage. smile

tanstaafl.

Edit: Ooops... I forgot about the 1400+ files in the subdirectories also needing renaming, and these don't all have the same naming convention. However, the names fall into just two categories, so alternating two different keyboard macros takes care of them, although it is still one file at a time. Have to look carefully at each file before running the macro to be sure it is the correct macro. It's done now, took a bit over an hour.

What'll you bet that my next backup will take a bit longer with 2300+ renamed files to deal with. smile

db
Posted by: tfabris

Re: Mass File Rename - 03/11/2017 18:04

https://xkcd.com/1908/

https://xkcd.com/1205/
Posted by: tanstaafl.

Re: Mass File Rename - 03/11/2017 18:19

Originally Posted By: tfabris
Oh, God, that is SO me!

Also, this: (And I did check his math, it is correct.

tanstaafl.
Posted by: gbeer

Re: Mass File Rename - 04/11/2017 02:47

Originally Posted By: JBjorgen
That's what I was thinking too, Mark, but I think the chances of Doug installing a bash environment in windows to do a bash script are almost nil. Not sure if something similar is possible with a batch file?


In Windows, learning to use powershell is a better use of time, compared to trying to figure out the needed batch syntax.
Posted by: canuckInOR

Re: Mass File Rename - 06/11/2017 21:51

Originally Posted By: tfabris

That chart needs a 3rd axis -- aggravation.

About a month ago, I spent a week writing a TamperMonkey script to inject SVN commit summary info into JIRA bug-tracking pages. This is a 5s/weekly (or less) task. It only takes a couple seconds to look up that info, but every time I needed that info, and had to look it up, I could feel my stress levels rising because dammit, I shouldn't have to be doing this; the info should just be there already, and it's clear that whoever designed the workflow that I have to follow has never actually used this workflow. Gah... surrounded by idiots!

So now, I have the aggravation of dealing with my buggy TamperMonkey script (sometimes I end up with the SVN commit summary listed twice), but the amount of aggravation caused by that is low enough that it's not worth my time fixing the bugs. And since they're my bugs, I know that I don't have to deal with idiots if the aggravation does kick up a notch; again, keeping my stress levels lower. There's some benefit to being being the idiot, here. smile

Overall, I'm much happier, because even though I spent far more time on such a minor efficiency improvement than I will ever gain in return, my frustration and stress has decreased. And that was well worth the extra few thousand minutes.