|
Answer» ok i have windows xp home edition, i have this code
@echo off set random= if not '%random%'=='' set random=%random:~0,1% start C:\docume~1\********\desktop\copyof~1\%random%.txt
and it brings up a random txt file named of numbers from 1 to 9, the problem is, i only need 1 to 5, so how do i set it to only to go from 1 to 5?
using the "if not '%random%'=='' set random=%random:~0,1%" makes it use 1-9 (the "1%" in it sets it to use just the first DIGIT, which can be from 1 to 9, idk what the "~0" does though...)
would appreciate any help!Look at the help for Set the /A parameter allows you to do arithmetic
the modulo function is % so any number % 5 gives you the remainder after DIVISION by 5 -- a number in the range 0-4 Add 1 to it to get 1-5
Grahamjust so i dont SOMEHOW mess that up, can you give me an example to go with my batch? Thank you for your help!OK - HERES a quick demo
@echo off set /A randno=%RANDOM% %% 5 set /A randno=%randno% + 1
I have used the variable randno so it doesnt clash with the built-in variable %RANDOM%
Because % is 'special', it has to be DOUBLED within a batch file (on the commandline, you will only need a single %)
GrahamTHANK YOU VERY MUCH!
|