Page 1 of 1

Randomly generated file names

Posted: 19 Jul 2010 02:47
by phillid
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

Re: Randomly generated file names

Posted: 19 Jul 2010 03:19
by miskox
Replace

Code: Select all

set "oldname=<oldname.txt"


with

Code: Select all

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


Saso

Re: Randomly generated file names

Posted: 19 Jul 2010 04:21
by aGerman

Code: Select all

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

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

Regards
aGerman

Re: Randomly generated file names

Posted: 19 Jul 2010 06:44
by ghostmachine4
why do you want to do something that your school has banned. You trying to play punk?

Re: Randomly generated file names

Posted: 20 Jul 2010 23:46
by phillid
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