Randomly generated file names

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
phillid
Posts: 109
Joined: 03 Apr 2010 20:27
Location: Wellington, New Zealand
Contact:

Randomly generated file names

#1 Post by phillid » 19 Jul 2010 02:47

Hey. I've been trying to make a program that will automatically rename an executable that my school banned...
I have the following code:

Code: Select all

@echo off
set "oldname=<oldname.txt"
set "rand=%random%"
echo.
echo OK! Let's get %oldname% a new name!
echo.
echo The new name will be '%rand%'
echo.
rename %oldname%.exe %rand%.exe
echo %rand%>oldname.txt
pause


Whenever I try to run it, where the old name should be, it's blank. This means that it didn't load the contents of 'oldname.txt' properly. I've got no idea how to do this without a 'for' loop, which I find can be complicated etc, etc...

I could ramble on for ages, but I'll keep the dots there ;)

Please help!!
Thanks!!
:D

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: Randomly generated file names

#2 Post by miskox » 19 Jul 2010 03:19

Replace

Code: Select all

set "oldname=<oldname.txt"


with

Code: Select all

FOR /F %%i IN (oldname.txt) DO set oldname=%%i


Saso

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Randomly generated file names

#3 Post by aGerman » 19 Jul 2010 04:21

Code: Select all

set /p "oldname="<"oldname.txt"

... will read the first line of oldname.txt into variable oldname.

Regards
aGerman

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: Randomly generated file names

#4 Post by ghostmachine4 » 19 Jul 2010 06:44

why do you want to do something that your school has banned. You trying to play punk?

phillid
Posts: 109
Joined: 03 Apr 2010 20:27
Location: Wellington, New Zealand
Contact:

Re: Randomly generated file names

#5 Post by phillid » 20 Jul 2010 23:46

ghostmachine4 wrote:why do you want to do something that your school has banned. You trying to play punk?

:) No
There is this one teacher who is a real prick and blocks any program that has a certain name. There's nothing in the computer use agreement that we signed when enrolling that stated that we can't play games at lunch, so one of the other teachers lets us.

Thanks a lot, guys! It's working now!!!
:D :D :D

Post Reply