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

WinJake

New member
Local time
3:46 AM
Messages
21
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 :D
 

My Computer My Computer

Computer Manufacturer/Model Number
Toshiba Satellite L755
OS
Windows 7 Home Premium 64bit
Memory
500 GB
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 My Computer

Computer Manufacturer/Model Number
HP Media Center
OS
Windows 7 32 bit
CPU
AMD 5200+ dual core
Memory
2 GB
Graphics Card(s)
NVidia GeForce 6150SE 128 MB
Monitor(s) Displays
CRT
Screen Resolution
1280x1024
Hard Drives
500 GB Sata internal :

SIIG USB 3.0 docking stations w/WD Caviar Black 6 Gb/s drives
Keyboard
PS/2
Mouse
PS/2 Wheel Mouse
Other Info
SIIG USB 3.0 PCIexpress card.
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 My Computer

Computer type
PC/Desktop
OS
win 7 ultimate
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 My Computer

Computer Manufacturer/Model Number
Toshiba Satellite L755
OS
Windows 7 Home Premium 64bit
Memory
500 GB
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 E:DTUtils\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 My Computer

Computer type
PC/Desktop
OS
win 7 ultimate
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 My Computer

Computer Manufacturer/Model Number
HP Media Center
OS
Windows 7 32 bit
CPU
AMD 5200+ dual core
Memory
2 GB
Graphics Card(s)
NVidia GeForce 6150SE 128 MB
Monitor(s) Displays
CRT
Screen Resolution
1280x1024
Hard Drives
500 GB Sata internal :

SIIG USB 3.0 docking stations w/WD Caviar Black 6 Gb/s drives
Keyboard
PS/2
Mouse
PS/2 Wheel Mouse
Other Info
SIIG USB 3.0 PCIexpress card.
Back
Top