Jump to content

Random GUID Filename


Recommended Posts

I would like to rename a few thousand text files through batch to a randomly-generated GUID filename. Does anyone know how to do this? I'm thinking it might be possible by using a third-party command-line GUID generator and setting a variable to the program's output, then creating a FOR loop.

Link to comment
Share on other sites


Yes, I've found uuidgen.exe already. It outputs a single GUID without the brackets, so I redirected its output to a temporary file:

@echo off

:loop
uuidgen.exe > temp.dat
for /f %%i in (temp.dat) do set tempuuid=%%i
goto loop

That generates an infinite amount of GUID's for my use. My next step was to then call another batch file and do a "for" loop to rename all *.txt files to %tempguid%. That's when I first found out that "environmental variables" apply only to a single cmd.exe session. Any help is appreciated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...