DOS Bulk Filename & Randomization

Posted on 2007-10-19
Medium Priority
Last Modified: 2012-06-27
I've read some other threads about bulk renaming of files, but I can't find one that fits my situation perfectly.

I'm running WinXP SP2, in DOS (cmd.exe, anyway), I have a local directory with many .jpg files. I want to bulk rename them to a random number and keep the .jpg extension.

For example:
(06-01-01)003_3.JPG to uf5hs6k.jpg
DSC00952.JPG to opku4.jpg

I do not care about the length of the filename very much. I'd like to keep it fairly short and there are roughly 300 jpg files. My intent in the randomization of the file name is so that they are no longer in the alphanumeric order that they are currrently in. So, I don't want to bulk rename to a static name and increment a number (or letter) at some point. Thanks!
Question by:damijim
LVL 70

Expert Comment

ID: 20112814
Pfrank is a very flexible file renaming program - they claim it can do anything see http://www3.telus.net/pfrank/
LVL 70

Expert Comment

ID: 20112851
I don't know of any tool that will randomly assign names.   The simplest solution here is probably to write a short program in C+ or Basic that parses the directory and changes each file to a random name.   It's fairly simple to generate a random string in either language => so it could simply go through the directory and rename each file to <randomstring>.jpg

I'd add the Programming area to your zones and see if someone is willing to throw together a short program to do this for you :-)

... or you might provide some detail on WHAT your goal is here => you may be able to do what you want without actually renaming all of the files :-)

Author Comment

ID: 20112924
I may just end up SSH'ing to unix box and SSH'ing back into my local machine to do it. I'm trying to PFrank thing out right now.

My goal: I have a program (not mine - already compiled) that goes through each file and processes them one by one in order of name, but I want them processed in random order (not an option in the program).
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 20112929
I was hoping for a fairly simple DOS command.. :)
LVL 70

Expert Comment

ID: 20112940
I just played around with PFrank a bit => it does a lot of things ... but choosing a Random name doesn't seem to be one of them :-)

... Perhaps you should write the author and point out that you found something it can't do !! --> he may just add the feature for you :-)

There aren't any simple DOS commands that will do this ... it is (as I suspect you know) a rather unusual request :-)

Author Comment

ID: 20112978
yeah, I can't find a way to do it in PFrank either.

I was thinking in PFrank, I could just use a few of the bulk renames.. like "only keep 4th and 5th char in prefix" then do like something and then some other command, but I don't know... i don't think it can do it... eitherway, when I start PFrank, it complains about not finding "PFrank\PFrankUser.py"... I'm assuming it needs python installed too?
Oct 19 2007 18:28:35    ***User Command Edit Problem
Error: No associated application for the python text file   'C:\Program Files\PFrank\PFrankUser.py'

Thanks anyway though! How do I add another zone to my topic? Running around SSH tunnels to get back to my corporate computer is a pain.
LVL 70

Expert Comment

ID: 20113030
Not sure how you add a zone ==> I haven't asked any questions since the new interface was added this year.   If there's not a button on your question's page to do it; I'm sure you can simply post a Community Support question asking that another zone be incorporated and a moderator will do it.

Author Comment

ID: 20113041
Nope, no button to add another zone.... unless someone can provide a simple DOS (or Windows) solution, I'll just take the directory home on my jump drive and do it in Linux after work. Thanks for trying. :)

Accepted Solution

ghostdog74 earned 2000 total points
ID: 20113385
here's a vbscript

strPrintable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\temp" 'directory where your jpgs are
Set objFolder = objFSO.GetFolder(strFolder)

For Each strFile In objFolder.Files
      If LCase(objFSO.GetExtensionName(strFile)) = "jpg" Then
            getStrRandom = GetRandomString(strPrintable,15)
            objFSO.MoveFile strFile,strFolder&"\"&getStrRandom&".jpg"
      End If

Function GetRandomString(str,iMaxLen)
      RandNum = Int((iMaxLength * Rnd) + 1) 'To calculate length of filename
      Do Until reach = RandNum
            RandLetter = Int((Len(strPrintable) * Rnd) + 1)       'get a random character
            ch=Mid(strPrintable,RandLetter,1) ' get that character
            strFileName = strFileName & ch
            reach = reach + 1
      GetRandomString = strFileName
End Function

Author Comment

ID: 20113394
I just resolved it in Linux... but I will try your script in Windows when I get back to work and award the points if it does. Thanks.

Linux solution:
ls | perl -nle '$s="";@n=split /\./ ;@chars=('a'..'z',0..9); $s.=$chars[rand @chars] for (1..8);rename($_,lc join(".",$s,$n[$#n]));'

It doesn't account for the possibility of two randomly generated filenames being the same, but you can test before and after with ls | wc - l
LVL 29

Expert Comment

ID: 20114649
"I was thinking in PFrank, I could just use a few of the bulk renames.. like "only keep 4th and 5th char in prefix" then do like something and then some other command"

There is a freeware app Flexible Renamer that can do this http://www.snapfiles.com/get/flexrenamer.html I use it quite a bit to rename multiple files at once, very fast and includes an undo function.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question