Jump to content

How To Select Random Images In One Of The Folder


Recommended Posts


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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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])])
    MsgBox(0, '', 'File(s) not found!')
Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...