Jump to content



Photo

Batch file rename folders

batch rename

  • Please log in to reply
1 reply to this topic

#1 hobblyhoy

hobblyhoy

    Neowinian

  • Joined: 05-June 05
  • Location: kiwi land

Posted 02 November 2012 - 23:34

Hi all,

I know this isn't technically programming but I didn't see anywhere it fit better. Feel free to move it.

Okay, so what I'm trying to accomplish is adding a random combination of numbers or letters or both to the beginning of a large list of files in batch. So far I've tried:

For /D %%i IN (*) DO rename "%%i" "%random%%%i"

But batch only runs a single random number with this and sets them all to that same number.

I've also tried adding something like "%%~zi" to the rename which grabs the file size but since it's a folder this returns 0.

The creation date tag "%%~ti" would work if chopped down to the last milliseconds but it appears the only way to even get at this value is to save it as a text file but it appears batch doesn't allow you to pull the content of a text file into a variable whilst inside of the FOR command.

and now I'm all out of ideas..


I have python installed so if anyone knows of a script to accomplish this I'm all ears but I haven't worked with it enough myself to accomplish this in a reasonable amount of time.

Thanks for reading,
~hobbly


#2 OP hobblyhoy

hobblyhoy

    Neowinian

  • Joined: 05-June 05
  • Location: kiwi land

Posted 03 November 2012 - 01:20

Managed to modify a python script to do what I need. In-case someone stumbles on this thread with a similar problem I used:


import os, random

path = '[location of folders]'
listing = os.listdir(path)
os.chdir('[location of folders]')
for infile in listing:
os.rename(infile, str(random.randint(10,99)) + infile)

Original credit to this guy.



Click here to login or here to register to remove this ad, it's free!