need help with another batch file

Discussion in 'Software' started by red death68, Feb 12, 2010.

  1. red death68

    red death68 Command Sergeant Major

    ok heres what i want to do there is a game i play that has kill badges that pop up everytime you make a kill u can change these badges so what i want to do is randomiz the badges so everytime i start the game it has a diff set of badges preferably not in any order

    i have 2 or 3 sets of badges to work with so i want to randomize them to bring up a differnt set of badges every game by placing them in the folder for the badges and only copying the originals so i dont ever lose my back ups

    any help would be apreciated
     
  2. GermanOne

    GermanOne Guest

    O my god, a posting without any dots and commas. I had to read it 15 times. ;)
    OK, think like a programmer. Where is the origin folder of your badges? What kind of file (extension) is it? How can you distinguish the different sets of badges? Where should the files be copied to? Have you to delete the former badges? ...

    Regards
    GermanOne
     
  3. red death68

    red death68 Command Sergeant Major

    ok first sorry about the punctuation i was in a hurry.
    second the file extention is .***
    third the the originals are all in folders in my docs
    third idk how to randomize it which is the main reason for posting
     
  4. red death68

    red death68 Command Sergeant Major

    ok heres what i got so far the problem is no matter what i do i cant figure out how to make it copy mutliple files and i keep getting the error "Invalid number of parameters" so im kinda at a lose and for once google aint helping any!

    XCOPY "%userprofile%\My Documents\games\crossfire mods\kill marks\km\" badge_headshot_gold.*** "%userprofile%\Desktop\practice folder"
    pause

    practice folder is where im testing the copy to to begin with but i will later change it to the actual folder that holds the files i want to replace

    the *** was t,g,a without the commas
     
  5. red death68

    red death68 Command Sergeant Major

    well update is after some poking around google i finaly got it to work for my first set of files. now all i have to do is get the randomization figured out ,and fix the permission issues my trial of windows 7 created.
     
  6. red death68

    red death68 Command Sergeant Major

    ok i got it to copy the files i want. the only problem is i cant get the exlude camand to work plz help and still need to figure out randomization
     
  7. GermanOne

    GermanOne Guest

    xcopy ... /EXCLUDE:file1+file2+file3


    Will put a random file of "%userprofile%\Desktop\practice folder" to %randFile%:
    Code:
    @echo off &setlocal
    pushd "%userprofile%\Desktop\practice folder"
    for /f "delims=: tokens=1*" %%a in ('dir /a-d /b^|findstr /n .') do set /a counter=%%a &set "file%%a=%%b"
    popd
    set /a randNo=%random%%%%counter%+1
    call set "randFile=%%file%randNo%%%
    echo %randFile%
    pause
    
    BTW: A file extension .*** is impossible (because * is forbidden to use for filenames).
     
  8. red death68

    red death68 Command Sergeant Major

    o i didnt know it was forbiden it happens to be the extension of my image files for the badges.

    and im still a nub when it comes to batch can u explin the batch code u posted just a bit?
     
  9. GermanOne

    GermanOne Guest

    Hope so.
    You should know the output of DIR /B. This output will be redirected to the FINDSTR command. The option /N add a line number in front of each line.
    Say the output of DIR /B is:
    Code:
    file_a.ext
    file_b.ext
    
    then you'll get using FINDSTR /N:
    Code:
    1:file_a.ext
    2:file_b.ext
    
    Now we use the colon as the delimiter in the FOR loop. So %%a becomes the number (1, 2, ...) and %%b becomes the file name.
    That means finally %counter% contents the number of found files (greatest line number). For the file variables we create something like an array. The variable name "file%%a" becomes "file1, file2, ...".

    Now you have to calculate a random number between 1 and %counter%. The content of %random% is a random number of your system. Now we use the modulo function from %random% and %counter% then add 1 and you got it.

    Say %randNo% is 2 then
    Code:
    call set "randFile=%%file%randNo%%%"
    
    becomes
    Code:
    set "randFile=%file2%"
    
    and %file2% contents one of the files.

    Thats it.
     
  10. red death68

    red death68 Command Sergeant Major

    ok so how do i incorperate it into this batch for copying my files

    XCOPY "%userprofile%\My Documents\games\crossfire mods\kill marks\km" "%userprofile%\Desktop\practice folder" /Y
    pause
    XCOPY "%userprofile%\My Documents\games\crossfire mods\Mark\Marks" "%userprofile%\Desktop\practice folder" /Y
    pause


    the pauses are diagnostic like u suggested in another thread and the xcopy cammand is set to my practice directory which ill change once the randomization has been incoperated.

    im glad theres someone like you who knows what their doing with batch google barley helped
     
  11. GermanOne

    GermanOne Guest

    Hmm, sry but I can't figure out the meaning (german translation) of "incoperated"?!

    Do you want to copy only one random file from "%userprofile%\My Documents\games\crossfire mods\Mark\Marks" and one random file from "%userprofile%\My Documents\games\crossfire mods\kill marks\km"?
    Code:
    @echo off &setlocal
    
    pushd "%userprofile%\My Documents\games\crossfire mods\kill marks\km"
    for /f "delims=: tokens=1*" %%a in ('dir /a-d /b^|findstr /n .') do set /a counter=%%a &set "file%%a=%%b"
    popd
    set /a randNo=%random%%%%counter%+1
    call set "randFile=%%file%randNo%%%
    copy "%userprofile%\My Documents\games\crossfire mods\kill marks\km\%randFile%" "%userprofile%\Desktop\practice folder\%randFile%"
    
    pushd "%userprofile%\My Documents\games\crossfire mods\Mark\Marks"
    for /f "delims=: tokens=1*" %%a in ('dir /a-d /b^|findstr /n .') do set /a counter=%%a &set "file%%a=%%b"
    popd
    set /a randNo=%random%%%%counter%+1
    call set "randFile=%%file%randNo%%%
    copy "%userprofile%\My Documents\games\crossfire mods\Mark\Marks\%randFile%" "%userprofile%\Desktop\practice folder\%randFile%"
    
     
  12. red death68

    red death68 Command Sergeant Major

    no copy all the files from that or all the files from another folder which is why i want it randomized
     
  13. GermanOne

    GermanOne Guest

    Hope that's what you want.
    Code:
    @echo off &setlocal
    :: number of folders:
    set n=2
    
    :: calculate a number between 1 and n
    set /a rand=%random%%%%n%+1
    
    ::jump to the label with the calculated number
    goto copy%rand%
    
    :copy1
    XCOPY "%userprofile%\My Documents\games\crossfire mods\kill marks\km" "%userprofile%\Desktop\practice folder" /Y
    goto end
    
    :copy2
    XCOPY "%userprofile%\My Documents\games\crossfire mods\Mark\Marks" "%userprofile%\Desktop\practice folder" /Y
    goto end
    
    :end
    
     
  14. red death68

    red death68 Command Sergeant Major

    thnx for the help but it only seems to be copying a single folder no matter how often i test run it
     
  15. GermanOne

    GermanOne Guest

    I explained you how to copy a randomized file from files of a single folder. I also explained you how to copy all files of a randomized folder. I don't understand what else you want to do?!
     
  16. red death68

    red death68 Command Sergeant Major

    hmm.... idk ill figure it out eventualy but one other question if i wanted to add another folder to the mix what would i change?
     
  17. GermanOne

    GermanOne Guest

    The number of folders would be 3 and you have to add a new label ( :copy3 ) with the new contents.
    Code:
    @echo off &setlocal
    :: number of folders:
    set n=3
    
    :: calculate a number between 1 and n
    set /a rand=%random%%%%n%+1
    
    ::jump to the label with the calculated number
    goto copy%rand%
    
    :copy1
    XCOPY "%userprofile%\My Documents\games\crossfire mods\kill marks\km" "%userprofile%\Desktop\practice folder" /Y
    goto end
    
    :copy2
    XCOPY "%userprofile%\My Documents\games\crossfire mods\Mark\Marks" "%userprofile%\Desktop\practice folder" /Y
    goto end
    
    :copy3
    XCOPY "??? your 3rd folder ???" "%userprofile%\Desktop\practice folder" /Y
    goto end
    
    :end
    
     
  18. red death68

    red death68 Command Sergeant Major

    thats what i thought but i wasnt sure thnx for the help as always your great with batch ill figure out the random problem after my hw is done and ill post if anything changes to make it work or not work
     
  19. GermanOne

    GermanOne Guest

    Sometimes the variable %random% contains nearly the same number. I've tried to figure out why, but no idea.
    A solution could be to call the %random% once before. Try beginning your batch with
    Code:
    @echo off &setlocal
    echo %random%>nul
    ...
    
     
  20. red death68

    red death68 Command Sergeant Major

    well it very rarley randomizes but it does once in a while

    what if i expanded the number of lines and repeated the copy lines so theres a better chance of getting it over and over sumtin like this


     
  21. GermanOne

    GermanOne Guest

    Maybe it would help.
    Otherwise you could randomize the randomizing. Replace the calculation part:
    Code:
    :: calculate a number between 1 and n
    set /a rand1=%random%%%10+%n%
    set /a rand2=%random%%%10+%n%
    set /a rand3=%random%%%10+%n%
    set /a rand4=%rand1%%rand2%%rand3%
    set /a rand=%rand4%%%%n%+1
    
     
  22. red death68

    red death68 Command Sergeant Major

    ill see how your suggestions works then if it comes to it maybe ill combine both of our ideas
     
  23. red death68

    red death68 Command Sergeant Major

    lol i combined both methods for better chances but it works ty very very much for all the help i hope next time i have a batch idea i wont need to post ill actualy know what im doing
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds