I need a batch file to open a random file within a certain folder/path


  1. Posts : 21
    Windows 7 Home Premium 64bit
       #1

    I need a batch file to open a random file within a certain folder/path


    I want a batch to select and open a random link file in a folder i have. All the links are music videos I like to listen to, and I kind of want to just have an option for 'surprise me!'.
    I can change the file names if I have to, and I have a basic batch file ability. I know the simple commands, but nothing of the variables, signs-involving commands (&%!?), etc.

    Also, I want to learn a whole lot more about programming/java/batch file, so it'd be awesome if any code could be explained. Thank you, in advance
      My Computer


  2. Posts : 5,092
    Windows 7 32 bit
       #2

    There's a free Windows scripting language called Autoit3 that would do this task easily using these functons:

    Random
    _FileListToArray

    AutoIt - AutoItScript


    It has a Basic like syntax and is easy to learn.

    Another popular scripting for Windows is AutoHotkey
    AutoHotkey: macro and automation Windows scripting language

    The syntax can be confusing but it has object support and is more powerful.

    Of course there are tons of others for Windows:
    Rexx
    Python
    Perl
    Ruby

    Here's a list. The details for each tell which OS are supported:
    Free Programming Languages - Freebyte's Guide to
      My Computer


  3. Posts : 2
    win 7 ultimate
       #3

    Post the name of the folder and the names of the files in it.
    I will then post back a .bat file that you can copy and use.
      My Computer


  4. Posts : 21
    Windows 7 Home Premium 64bit
    Thread Starter
       #4

    I can try the autoit script, i saw it a while ago when I did a different batch file mission, but I knew it wouldnt work for my purpose and I didnt even try it then.

    C:\Users\Owner\Desktop\MineMusic is the folder path and the files in it are a collection of random song names. I have probably 50-100 in it, but I dont really care about the file names if i just make it all random. They are .url internet shortcuts, btw.
      My Computer


  5. Posts : 2
    win 7 ultimate
       #5

    well here's a .bat that will get you on the way .. you will need to change all the folder links and add a player at the end

    @echo off
    cls
    E:\DTREE\dtree.exe /y ETUtils\DTPics\net\picxx.jpg
    setlocal enabledelayedexpansion

    set /a rand=%random%%%31+1

    pushd E:\dtutils\dtpics\net\

    set nbr=1
    for /f "delims=*" %%1 in ('dir /a-d /b *.jpg') do (
    set file=%%1
    set /a nbr+=1
    if !nbr! gtr !rand! goto getout
    )

    :getout
    xcopy /y "%file%" "E:\DTUtils\dtpics\net\picxx.jpg"
      My Computer


  6. Posts : 5,092
    Windows 7 32 bit
       #6

    WinJake said:
    I can try the autoit script, i saw it a while ago when I did a different batch file mission, but I knew it wouldnt work for my purpose and I didnt even try it then.
    It can do it quite easily. Write as much of the script as you can and post it here:
    General Help and Support - AutoIt Forums

    We all get stuck when trying to do something the first time. But if you are interesting in programming the key is to get a simple version to work or nearly work. This gives you a test bed to learn how to do the new or difficult thing. Once you understand how it works you may just fix the program or come up with a better design. Programming is all about learning curve. To progress you need to be willing to absorb some.

    Good luck with it. :)
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 20:38.
Find Us