Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Rename lots of files in one click

I have thousands of images that I wish to batch rename numerically.

The issue is all the dozens of images I have saved have osbscure filenames like in this screenshot

I want the output(s) to be something like: 0001, 0002, or 001, 002, etc

What would be the best way to achieve/do this?

share|improve this question

marked as duplicate by Shinrai, Indrek, 8088, Ƭᴇcʜιᴇ007, bwDraco Oct 1 '12 at 23:59

This question was marked as an exact duplicate of an existing question.

See also this and this. – Scott Oct 1 '12 at 23:50

You're on Windows, so you could do it this way with Hamilton C shell:

@ n = 1
foreach i ( *.jpg )
   mv $i $printf("%04d.jpg", n++)

The free demo version is all you need. (Full disclosure: I'm the author.)

share|improve this answer

Assuming pure Windows (i.e., no Cygwin, et al.) and that you don't want to or can't install anything to do it with, I'd suggest using a Visual Basic script to do the job. You might try something like:

 targetDir = WScript.Arguments.Item(0)
 WScript.Echo "Operating on files in " + targetDir
 Set fsh = CreateObject("Scripting.FileSystemObject")
 Set targetFiles = fsh.GetFolder(targetDir).Files
 ZeroPadWidth = Len(targetFiles.Count)
 FileNumber   = 0
 For Each File In targetFiles
   FileNumber = FileNumber + 1
   NewName = targetDir & "\"
   For I = 1 To ZeroPadWidth - Len(FileNumber)
     NewName = NewName & "0"
   NewName = NewName & FileNumber
   WScript.Echo "Renaming " & targetDir & "\" & File.Name & ": " & NewName

Put that into a file, e.g. "rename.vbs"; then, call it from the command line, with the target directory as the sole argument, like this:

 c:\Users\Username\Desktop> cscript rename.vbs "c:\target\directory"

It will produce filenames which are ordered numerically and left-padded with zeroes; if you have a directory with a thousand files in it, you'll get names ranging from 0001, 0002...0999, 1000.

No warranty, but it should do what you need. If it doesn't, let me know. (And make a safe copy of the target directory just in case; I've tested this a bit, and it should be OK, but there's always the possibility of the bug I didn't catch.)

Hope this helps! (If it does, I hope you'll take Shinrai's point about accept rates to heart.)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged .