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.


Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
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: 646
Thanks: 27
Thanked 80 Times in 74 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?
__________________
I.think(code);
I.eat(code.spaghetti);
Reply With Quote
  #3  
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: 319
Thanks: 4
Thanked 72 Times in 68 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
:sub1
rem For each found file set counter + 1.
set /a "counter+=1"
goto :eof
:: end of sub1

:: start of sub2
: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
  #4  
Old 04-29-14, 14:05
Massimo73 Massimo73 is offline
Private E-2
 
Join Date: Apr 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Batch program - How could i open a random image from a specified folder?

For an avi file this would be the batch i use, you can change the extension or use %1 and pass it as an argument.

Cheers,
Massimo


:: --snip--- start of batch
@echo off
setlocal enableDelayedExpansion
:: start of main


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 "rdm=%random%"
set "rdm=%random%"

::build "array" of files
set fileCnt=0
for /f "delims=" %%i in ('dir /b /s *.avi *.mpg *.wmv *.mkv *.mp4 *.mov *.m4v') do (
set /a fileCnt+=1
set "fileArray!fileCnt!=%%i"
)

rem This function gives a value from 1 to upper bound of files
set /a rdNum=(%rdm%*%fileCnt%/32767)+1
echo "total number of files = %fileCnt%"
echo "random files # = %rdNum%"

rem Start a random file
call :selectOneFile

goto :eof
:: end of main


:: start of selectOneFile
:selectOneFile

set fileName=!fileArray%rdNum%!
echo %fileName%
start "" "%fileName%"
pause
exit
)

goto :eof
:: end of selectOneFile

:eof
:: -snap--- end of batch
Reply With Quote
Reply

Tags
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:23.

MajorGeeks.Com Menu

MajorGeeks.Com \ 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 \ NEW! PC Games \ System Tools \ Macintosh \ Demonews.Com \ Top Downloads

MajorGeeks.Com \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

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


All content Copyright © MajorGeeks.com source code Powered by vBulletin® Version 3.8.4
Copyright © 2009 vBulletin Solutions, Inc. All rights reserved.
Ad Management by RedTyger