#369686 - 01/11/2017 20:19
Mass File Rename
|
carpal tunnel
Registered: 08/07/1999
Posts: 5546
Loc: Ajijic, Mexico
|
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.
_________________________
"There Ain't No Such Thing As A Free Lunch"
|
Top
|
|
|
|
#369687 - 02/11/2017 01:03
Re: Mass File Rename
[Re: tanstaafl.]
|
old hand
Registered: 27/02/2003
Posts: 776
Loc: Washington, DC metro
|
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
@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!"
)
|
Top
|
|
|
|
#369700 - 03/11/2017 01:50
Re: Mass File Rename
[Re: tanstaafl.]
|
carpal tunnel
Registered: 08/03/2000
Posts: 12338
Loc: Sterling, VA
|
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.
_________________________
Matt
|
Top
|
|
|
|
#369701 - 03/11/2017 03:12
Re: Mass File Rename
[Re: Dignan]
|
carpal tunnel
Registered: 08/07/1999
Posts: 5546
Loc: Ajijic, Mexico
|
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.
_________________________
"There Ain't No Such Thing As A Free Lunch"
|
Top
|
|
|
|
#369706 - 03/11/2017 11:12
Re: Mass File Rename
[Re: Dignan]
|
pooh-bah
Registered: 27/02/2004
Posts: 1913
Loc: London
|
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.
|
Top
|
|
|
|
#369708 - 03/11/2017 13:39
Re: Mass File Rename
[Re: tanstaafl.]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14491
Loc: Canada
|
#!/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.
|
Top
|
|
|
|
#369710 - 03/11/2017 15:13
Re: Mass File Rename
[Re: tanstaafl.]
|
carpal tunnel
Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
|
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?
_________________________
~ John
|
Top
|
|
|
|
#369711 - 03/11/2017 16:41
Re: Mass File Rename
[Re: JBjorgen]
|
carpal tunnel
Registered: 08/07/1999
Posts: 5546
Loc: Ajijic, Mexico
|
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... 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. 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. db
Edited by tanstaafl. (03/11/2017 18:09)
_________________________
"There Ain't No Such Thing As A Free Lunch"
|
Top
|
|
|
|
#369712 - 03/11/2017 18:04
Re: Mass File Rename
[Re: tanstaafl.]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31596
Loc: Seattle, WA
|
|
Top
|
|
|
|
#369713 - 03/11/2017 18:19
Re: Mass File Rename
[Re: tfabris]
|
carpal tunnel
Registered: 08/07/1999
Posts: 5546
Loc: Ajijic, Mexico
|
Oh, God, that is SO me! Also, this: (And I did check his math, it is correct. tanstaafl.
Attachments
Edited by tanstaafl. (03/11/2017 18:23)
_________________________
"There Ain't No Such Thing As A Free Lunch"
|
Top
|
|
|
|
#369724 - 04/11/2017 02:47
Re: Mass File Rename
[Re: JBjorgen]
|
carpal tunnel
Registered: 17/12/2000
Posts: 2665
Loc: Manteca, California
|
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.
_________________________
Glenn
|
Top
|
|
|
|
#369749 - 06/11/2017 21:51
Re: Mass File Rename
[Re: tfabris]
|
carpal tunnel
Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
|
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. 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.
|
Top
|
|
|
|
|
|