Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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

26 May 2014   #1
WinJake

Windows 7 Home Premium 64bit
 
 
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 System SpecsSystem Spec
.
26 May 2014   #2
MilesAhead

Windows 7 32 bit
 
 

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 System SpecsSystem Spec
26 May 2014   #3
needamiracle

win 7 ultimate
 
 

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 System SpecsSystem Spec
.

26 May 2014   #4
WinJake

Windows 7 Home Premium 64bit
 
 

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 System SpecsSystem Spec
26 May 2014   #5
needamiracle

win 7 ultimate
 
 

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 System SpecsSystem Spec
26 May 2014   #6
MilesAhead

Windows 7 32 bit
 
 

Quote   Quote: Originally Posted by WinJake View Post
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 System SpecsSystem Spec
Reply

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




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Cannot Open File...The system cannot find the path specified
Hello, could somebody please help me? So background story here: I have a SSD for boot and applications, and a HDD for storage. I recently changed my "Location" for Pictures, Movies, Documents, and also Downloads. I changed the "Locations" to my 1TB HDD. I did not make a junction, I just created...
General Discussion
Batch file to open multiple browsers
Hello, I need 10 different browsers open and after some searching found a way to write a batch file which worked but with a couple of problems. The problem is it opens them all at once and several of the browsers crash. So I tried adding a ping after each one as follows: @echo off start /D...
Browsers & Mail
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
batch file open file for program in the startup folder
I have a computer that is a drone specifically for an outside LED sign. This computer is designed to never shut off and doesn't have any other program on it besides Operating System and the sign software. I need to create a batch file that I can place in the "start-up" folder that will open the...
General Discussion
Batch file to create a folder with name of the time.
I'm trying to write a batch file that when run creates a folder named "Backup" followed by the time it was created, and then copies files to that folder. When I run md "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Backups\Backup %DATE%\" xcopy /e /v /y...
Backup and Restore
Batch File to Open ALL Links in Folder
I have a few LNK files in the same folder and would like to write a batch file that opens all of these links without explicitly having each link listed in the batch file. Is there a way to open all links in one folder? I would presume so, considering Windows has for the most part always had a...
General Discussion


Our Sites

Site Links

About Us

Find 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 09:26.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App