MajorGeeks Support Forums

Go Back   MajorGeeks Support Forums > ----------= PC, Desktop and Laptop Support =---------- > Software
Register FAQ Members List Calendar Casino Mark Forums Read

Software Software such as operating systems like Windows XP, Windows Vista, Windows 7 etc., or specific programs.

Thread Tools Display Modes
Old 02-05-09, 18:56
syeuk2002 syeuk2002 is offline
Private E-2
Join Date: Feb 2008
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Default Batch program - How could i open a random image from a specified folder?

Here is what i am trying to do...

I have all of the covers for my DVD's in a folder on the PC. In order to decided what to watch i flick through these images.

I was wondering, say if i have all the dvd covers in the folder C:\DVDCOVERS

Could i then write a batch file to open a random image file?

I have found 1 method on-line but it requires that i rename all of the images as numbers. I don't really want to do that.

Please help!!

Thanks x
Reply With Quote
Sponsored links
Old 02-13-09, 12:49
PC-XT's Avatar
PC-XT PC-XT is offline
Master Sergeant
Join Date: Oct 2007
Location: on a farm
Posts: 645
Thanks: 27
Thanked 77 Times in 73 Posts
Default Re: Batch program - How could i open a random image from a specified folder?

You could have a list of them in a file (or generate one with dir) and try possibly using a variation of that method you found to find a particular file name to show by taking that line of the file?
Reply With Quote
Old 02-27-09, 18:07
GermanOne's Avatar
GermanOne GermanOne is offline
Major Geek's Coding Genius Extraordinaire
Join Date: Feb 2009
Location: Thuringia / Germany
Posts: 313
Thanks: 4
Thanked 67 Times in 64 Posts
Default Re: Batch program - How could i open a random image from a specified folder?

Hi, you can try this:

:: --snip--- start of batch

@echo off & setlocal
:: start of main
rem Set your path here:
set "workDir=C:\DVDCOVERS"

rem Read the %random%, two times is'nt a mistake! Why? Ask Bill.
rem In fact at the first time %random% is nearly the same.
@set /a "rdm=%random%"
set /a "rdm=%random%"

rem Push to your path.
pushd "%workDir%"

rem Count all files in your path. (dir with /b shows only the filenames)
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do call :sub1

rem This function gives a value from 1 to upper bound of files
set /a "rdNum=(%rdm%*%counter%/32767)+1"

rem Start a random file
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do set "fileName=%%i" &call :sub2

rem Pop back from your path.
popd "%workDir%"

goto :eof
:: end of main

:: start of sub1
rem For each found file set counter + 1.
set /a "counter+=1"
goto :eof
:: end of sub1

:: start of sub2
rem 1st: count again,
rem 2nd: if counted number equals random number then start the file.
set /a "counter+=1"
if %counter%==%rdNum% (start "" "%fileName%")
goto :eof
:: end of sub2

:: -snap--- end of batch

Hope that helps and regards from Germany.
Reply With Quote

batch file random

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch size image editing got2run Software 3 01-24-09 12:50
Program files folder being populated with inreadable image files peterianb Malware Removal 3 09-05-08 21:38
batch RAR program? Keyser Söze Software 2 01-24-07 21:11
Need batch launching program bigbazza Software 6 06-15-06 16:29
Batch File: Storing Folder Name in Variable SimpleMan46 Software 12 06-30-04 08:38

All times are GMT -5. The time now is 23:13.

MajorGeeks.Com Home Page
| Admin Tools | All In One | Anti-Spyware | Anti-Virus | Appearance | Backup | Benchmarking | BIOS | Browsers | Covert Ops |
Data Recovery | Diagnostics | Drive Cleaners | Drive Utilities | Drivers | Driver Tools Ergonomics | Firewalls | Games | Game Tweaks | Graphics | Input Devices | Internet Tools | Macintosh | Mail Utilities | Memory | Messaging | Monitoring | Microsoft | Multimedia | Networking | Office Tools | Process Management | Processor | Registry | Security | System Info | Toys | Video | Miscellaneous
Powered by vBulletin® Version 3.8.4
Copyright © 2009 vBulletin Solutions, Inc. All rights reserved.
Ad Management by RedTyger