Jump to content
Sign in to follow this  
PHPWarner

How To Select Random Images In One Of The Folder

Recommended Posts

PHPWarner

Hello,

I need code sample for select one of the image on selected folder.

For example, there are 20 images in C:\Images folder. I need to random select one of the image on this folder. 20 images are completely example so I guess the script should count total images on the selected folder and random select.

Many thanks in advice.

Share this post


Link to post
Share on other sites
PHPWarner

Update: I did sample code for explain my problem.

$PicFolder = "C:\Images"
$ImagesList = _FileListToArray($PicFolder)
$Img = Random(1, $ImagesList[0], 1)
$iPic = $PicFolder & "\" & $Img & ".jpg"

This code selecting random image on C:\Images but all image names should be 1.jpg 2.jpg 3.jpg etc... If one of the image name is DSC_01.jpg it is not selecting this image. So need more global selection code.

Thanks now.

Edited by PHPWarner

Share this post


Link to post
Share on other sites
Yashied

It is very simple.

#Include <File.au3>

$FileList = _FileListToArray(@WindowsDir & '\Web\Wallpaper', '*.*', 1)
If (Not @error) And ($FileList[0]) Then
    MsgBox(0, '', $FileList[Random(1, $FileList[0])])
Else
    MsgBox(0, '', 'File(s) not found!')
EndIf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.