It was not one of Explorer’s design goals to provide a Turing-complete interface for bulk file renaming

Date:August 3, 2007 / year-entry #284
Tags:other
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20070803-00/?p=25723
Comments:    41
Summary:Somebody wanted to append an extension to all files in a directory and couldn't find a way to do this type of bulk rename in Explorer. On the other hand, it's pretty simple from the command prompt: ren * *.ext The person then asked, "Can we get this and other multi-file operations added to Explorer?"...

Somebody wanted to append an extension to all files in a directory and couldn't find a way to do this type of bulk rename in Explorer. On the other hand, it's pretty simple from the command prompt:

ren * *.ext

The person then asked, "Can we get this and other multi-file operations added to Explorer?"

  • "There should be a way to rename a large number of files, appending .ext to the name of each file (for example changing x to x.ext)."

  • "There should be a way to rename a large number of files, changing ABC to XYZ in each name (for example changing Customer_ABC_History.doc to Customer_XYZ_History.doc)."

  • "There should be a way to rename a large number of files, swapping the first two words in each file name (for example changing Bob Smith.vcf to Smith, Bob.vcf)."

  • "There should be a way to rename a large number of files, naming each file after the date and time it was created (for example IMG_2150.JPG becomes Photo December 25, 2004 0735am.JPG)."

  • "There should be a way to rename a large number of files, inserting the word (Provisional) after the first word (for example changing Recommendations for Smith account.doc to Recommendations (Provisional) for Smith account.doc.)"

  • "There should be a way to rename a large number of files, changing the case of each file name (for example changing Recommendations for Smith account.doc to Recommendations For Smith Account.doc.)" (Note that the above case change is incorrect, but computers don't know that.)

  • "There should be a way to rename a large number of files, inserting the name of the album extracted from the mp3 metadata before the title (for example changing Tick Tock.mp3 to Beautiful Ride - Tick Tock.mp3.)"

It was not one of Explorer's design goals to provide a Turing-complete interface for bulk file renaming. (Remember, you don't know what you do until you know what you don't do.)

Explorer does an extremely simple type of bulk rename: Renumbering a group of files. If that doesn't suit your needs, you can use the command prompt.

ren * *.ext

Or you can write a batch file that does some editing before doing the rename.

for %%i in (*.doc) do call :fancy %%i
goto :eof
:fancy
set _=%1
ren %_% %_:ABC=XYZ%

You can generate a list of files to rename and then load it into your favorite editor to turn it into a batch file to execute.

dir /b *.vcf > files.cmd
vi files.cmd
:%s/^\([^ ]*\) \([^ ]*\)\(.*\)/ren "\1 \2\3" "\2 \1\3"
ZZ
files

Or you can write a program in your favorite language that does the most awesome-fancy renaming the world has ever seen.


Comments (41)
  1. Neil says:

    I predict 6 editor wars posts (not including those who say you should be using sed, Perl etc.)

  2. acc says:

    ..or, if you don’t want to write code, you can simply use Total Commander which actually has a fully featured and powerful "Multi-Rename Tool" with the immediate preview:

    http://www.ghisler.ch/wiki/index.php/Multi-Rename_Tool

  3. Bahbar says:

    I had one of those issues recently.

    I wanted to rename a list of photos, and I wanted to have the file name sequences match the shot date (because my camera fills numbering holes in the sequence when you delete some pictures to make room)

    Unfortunately, the creation date was the one of the copy to the disk, not the shot date. Explorer actually shows the shot date, and can even sort by that. I tried to use a command line tool. I had no idea how to get the shot date out of a cmd though…

    In the end, I had to do some pretty horrible things: open all the files (or as much as could fit the editor I was using, we are talking hundreds of multi-meg jpgs here), copy the list of the filenames in the editor, and use /that/ as a script source (because the list was sorted by the order of the drop, and it kept the original explorer ordering)… yuck.

    I would have enjoyed a bulk renumbering in explorer, but then again, an option to dir accessing the files properties would have helped too. So would a way to paste the file name selection instead of the files themselves.

    There must be an easier way I missed…

    I guess I could write a program, huh ?

    [Sequential renumbering is the only thing Explorer can do, and that’s what you wanted — view the files in Explorer, sort by “Date taken”, select all, bulk rename. That should do it. (I don’t think you want the DIR command loading shell extensions.) -Raymond]
  4. AndyC says:

    "Or you can write a program in your favorite language that does the most awesome-fancy renaming the world has ever seen. "

    Like this one?

    http://worsethanfailure.com/Articles/My-Kind-of-copyFile.aspx

    Brillant. :)

  5. Sinan Unur says:

    For all sorts of interesting renaming possibilities, Lupas Rename (http://rename.lupasfreeware.org/) can’t be beat.

    As for renaming photo files to EXIF date, if you already have Perl installed and are willing to install an additional module Image::ExifTool, it is easy to write a script to do the bulk rename. The example I have at http://www.unur.com/comp/ppp/exren.html has been working for me for a long time (in conjunction with the Command Prompt Here PowerToy). You might also find http://www.unur.com/comp/ppp/dccp.html useful.

    Hope this helps.

    Sinan

  6. Gabe says:

    I think Bahbar has an interesting idea. If Explorer could just copy and paste filenames, you could select a bunch of files, copy the filenames, paste them into your editor, change them as you see fit, copy them again, and then paste them into the same selected files in Explorer.

    Even if the whole paste thing is a but too pie-in-the-sky, making it so that Explorer also put the filenames into the clipboard as text is a feature I often wish for.

    [Oh, you mean Copy as path? -Raymond]
  7. Sinan Unur says:

    Gabe:

    Take a look at http://www.gabrieleponti.com/software/ for SendTo toys. AFAIK, Microsoft’s SendToX PowerToy for Win95 has problems on XP, but Gabriele’s extension works beautifuly.

    I don’t think it is necessary or desirable for Microsoft to build all this functionality into Explorer.

    Sinan

  8. Bahbar says:

    [Sequential renumbering is the only thing Explorer can do, and that’s what you wanted — view the files in Explorer, sort by "Date taken", select all, bulk rename. That should do it. (I don’t think you want the DIR command loading shell extensions.) -Raymond]

    Hehe, I just tried a bulk rename and I messed up. Trying to undo the operation undoes a single rename… And there is a low limit (10) to the number of undo iterations one can do. Doh!

    As to DIR not loading shell extensions, I agree, I do not want shell extensions loading. I only added it as an option because you mentioned it as a replacement for data source (along with cmd globbing).

  9. David Walker says:

    Gabe, the Windows "Power Toys" can send a filename or a list of filenames to the clipboard.  Very similar to the toys that Sinan linked to.  

    I didn’t know Explorer could natively do Bulk Rename to sequentially rename files.  XP doesn’t seem to do this, so maybe it’s only Vista, and/or maybe it only works with pictures, but all of the Bulk Rename things I see in Google are freeware downloads.  I’ll have to learn Vista some day…

    But sure, we want Explorer to be all things to all people, and ALSO be simple to use!  :-)

  10. Bahbar says:

    @Gabe: I really do not think it is the explorer’s job to do the conversion. I just wish something like notepad (to take one) would handle the paste of multiple files as a request to paste the file names… It does so for a single file anyways.

    But I could not think of a single program that would do that. All file handling programs would just open the files :(

    @Sinan: Thanks for the pointers.

  11. Bahbar says:

    @David Walker:

    XP does do it. Select a bunch of files, do a rename. Type your new name (graphically replacing a single file name). Enter. Look at all the selected files get renamed.

    Crude, but it would have helped me extract the data I wanted.

    Wow, and to think I almost never post.

  12. Mark says:

    If you are a Perl type, try Larry wall’s solution.

    Christiansen, Tom and Nathan Torkington. Perl Cookbook. O’Reilly, 1998. Chapter 9.9 Renaming Files.

    [Removed link to copyright violation; replaced with citation. -Raymond]
  13. Mikkin says:

    I sigh remembering when wildcard operations went away with the old File Manager, and dropping into DOS mode felt like progress into the past. On balance I found it a good thing, because I didn’t want grandma or the children (and other childlike persons of all ages) fooling with wildcards. They get into enough trouble with drag and drop.

  14. Sinan Unur says:

    Re: <a href="http://blogs.msdn.com/oldnewthing/archive/2007/08/03/4195888.aspx#4208682">Mark</a&gt;

    That site used to host illegal copies of O’Reilly books. IMHO, it would be nicer if you could avoid linking to such sites in the future.

    Sinan

  15. DriverDude says:

    “Oh, you mean Copy as path? -Raymond”

    Can of worms, opened.

    I read the article and it jives with my limited understanding of OLE and drag/drop. But… it doesn’t explain why, without any power toys, it is possible to drag a filename from Explorer into a Command Prompt on 2000 and XP, whereas on Vista we get a “no drop” icon.

    There is a drag/drop data viewer utility in the Win32 SDK. What puzzles me more is that it says XP and Vista’ Explorers are packing the same drag/drop data (or at least that’s what I think it says)

    What’s more, a while back I saw a mini-cmd prompt Sidebar gadget (for Vista, obviously) that accepts filename drag from Explorer.

    There’s a thread about this on Shell:Revealed but nobody with any authority has responded.

    [Each program decides what it does with the data. Some insert the file; some insert the file name. I fail to see how this is so mysterious. You can write a program that displays a rainbow when somebody drops a file on it. -Raymond]
  16. Scott says:

    Wow, I never knew you could do that bulk rename in the Explorer.

    And I doubt I’ll ever use it again, but still interesting.

  17. skst says:

    Rename Regular Expression uses regular expressions and shows you a preview of the renames. RRE’s not perfect, but it does what I need.

    http://www.12noon.com/renameregex.htm

  18. MadQ says:

    @Gabe: I actually wrote a simple shell extension to do just that. The shell hands the extension an IDataObject in IShellExtInit::Initialize(), and the extension just grabs all the file names and adds them as CF_UNICODETEXT to the IDataObject.

    I read the Copy As Path article, but I have to say that I’ve never come across the problems it mentions. Copying filenames from the shell and pasting them elsewhere is so natural I always completely forget that Explorer doesn’t support it until I’m using someone else’s PC. … and then spend the next ten minutes trying to figure out why it isn’t working.

  19. Might want to check out FileBoss from the Utility Factory for tons of file renaming operations:

    http://www.theutilityfactory.com/

  20. Leo Davidson says:

    You can do every one of the examples with Directory Opus (my favourite file manager). That includes the metadata stuff, wildcards, regexps, even renames via VBScript functions if you want to do something really esoteric, real-time results preview, saved presets, ability to create toolbar buttons which rename in a particular way via a single click, etc.

    It’s fair enough that Explorer doesn’t provide such functionality but I couldn’t live without it in a file manager after being used to it.

    Here are a couple of screenshots for anyone curious:

    http://nudel.dopus.com/opus9/page5.html#rename

  21. Adam says:

    Heh. If you’ve got ‘vi’ installed, you might like to try ‘moreutils'[0] which include ‘vipe'[1]. You can change your rename to:

    dir /b *.vcf | vipe | cmd

    :%s/^([^ ]*) ([^ ]*)(.*)/ren "1 23" "2 13"

    ZZ

    [0] http://kitenet.net/~joey/code/moreutils/

    [1] http://sinusforschung.com/cgi-bin/dwww/usr/share/man/man1/vipe.1.gz?type=man

  22. Yuhong Bao says:

    And nor it was one of the Macintosh Finder’s (or Lisa Office System’s for that matter) design goal. That was a disadvantage of the Mac’s GUI back in 1984. Thankfully then disks was small (only 400K floppies was used on the Mac then) and therefore there was not that many files on a disk. System 7 Pro introduced AppleScript to easily automate operations like this. And Mac OS X now have a Unix-style command line.

  23. I see a lot of interesting tools mentioned here.  

    My first choice would be PowerShell.  With it, I can do complex renames, with the full power of .Net backing me up.    And much, much more.

  24. Peter says:

    Personally, I’d do murder for the ability to filter files in a directory by wildcard (ala Konqueror), ie. type "c:tmp*.txt" into the address bar to see only the .txt files in that directory.

    But there comes a point when you’ve got to stop designing a product – unfortunately for me that came before my pet feature got added, but fortunately for me before all these other people’s ones.

  25. I wrote a shell extension to do just that.  It’s provided for free on codeproject.  The url is http://www.codeproject.com/shell/shswapl.asp

  26. Yuliy says:

    Peter: that capability has existed since DOS on the command line. "dir c:tmp*.txt" will give you the list you want

  27. I’m an Opus reseller, and I really think Opus has hit the mark of the File Manager for Power Users. Yes, Explorer isn’t designed to do this sort of stuff, and shouldn’t be either. But, that doesn’t mean that Explorer is the right tool for all users. It’s like complaining about MS Paint not offering filters and layers. It’s not designed for that, and it’s best if those who need those features simply use a tool designed for it rather than trying to design in those capabilities into a "beginner" tool.

  28. Xavi says:

    It was not one of Explorer’s design goals to

    provide a Turing-complete interface for bulk

    file renaming

    Why to carry the rename task into extremes?

    There are plenty of desired (rename)features. Yes, I agree that not every wish will and can be fulfilled, but there is still a plenty left that a file explorer could/should do.

    I don’t want to carry a batch of batches with me just to do some admin work on various PCs, and File explorer is a really poor tool.

    Turing-complete interface?

    Just let the file Word-guys talk to the FileExplorer-guys. If that doesn’t help, have a look at other file system tools.

  29. Harri says:

    There’s an extension bar named <a href="http://tools.tortoisesvn.net/StExBar">"StExBar"</a&gt; . And despite its bad name, it can do renames in explorer with regexes.

    And it can also "Copy as path": select the files, then hit on the button in the toolbar or use Ctrl-Shift-C to copy the full paths (or just filenames) to the clipboard.

  30. Dave C says:

    But… it doesn’t explain why, without any power

    >toys, it is possible to drag a filename from

    >Explorer into a Command Prompt on 2000 and XP,

    >whereas on Vista we get a "no drop" icon.

    I completely have to agree there, what I wouldn’t give to have that feature back in Vista.  From a Systems/Network administrators perspective the ability to drag and drop named to the command prompt saved me hours of time over the last few years.  Still throws me off every time, sad sad day.

  31. Chris Quirke says:

    The free CK Renamne utility does this sort of bulk renaming very, very well – and offers a neat "preview" so you can see what the names would look like as you make the alterations.

    Can append, substitute, change case, etc. No scripting or assembly required.

  32. KJK::Hyperion says:

    DriverDude: console windows are owned by a critical kernel process. Not only there are various hacks inside the core Win32 DLLs so that they never, ever, ever load third party DLLs (nor most trusted system DLLs for that matter) while inside said process (no, not hook DLLs, that’s a more general rule: you cannot install hooks in system processes no matter what), but the window manager makes no special distinction for console windows.

    The consequences are that the implementation has to be super-careful, and (in Vista and later) that all console windows have a high enough integrity label (don’t know whether "system-critical" or merely "high") that any dangerous interaction with them is forbidden

    It’s a horribly, horribly troublesome design that has caused pain, confusion and anger for fourteen years, and counting.

    (all misleading statements intentional. Do some damn footwork on your own, Wikipedia stooges)

  33. xplorer2 also has a decent mass renamer that can add all sorts of data in the filename, including file dates (all column information in fact)

    http://www.zabkat.com

    relevant demo at: http://zabkat.com/blog/wink/id3.htm

    </plug>

  34. bob says:

    Explorer might not have been designed for this, but in all honesty it hasn’t been designed but a whole lot of things, when it comes to (serious) file management.

    That’s why there are so many alternatives, one of them – and the best IMHO – being XYplorer, which features absolutely everything that’s been mentionning on your post (and more), only it can’t use the date created, only current date & date modified.

    More on all the rename features here:

    http://88.191.26.34/XYwiki/index.php/Rename_Special

  35. Igor says:

    Simply use Directory Opus instead of Explorer, problem solved.

    By the way, how about naming your photos more contructively than 20070808_134559.jpg?

  36. No, I’m not going to tell you how to be a successful blogger. No, I’m going to tell you how an organization can and should use blogs successfully. Microsoft is the world’s greatest blogging company. GMU is the world’s greatest blogging economics department.

  37. Thomas Tallyce says:

    And why does Explorer STILL not have a ‘print directory’ command, after all these years?

    Is it really a totally obscure need to print out a list of files in a folder, without having to use DOS commands or mess around doing print screens?

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index