Jump to content
akshatgupta

Loops and fileExists issue

Recommended Posts

akshatgupta

I want to save a screenshot of the screen in a particular folder with different names.

like img0, img1, img2,...

I tried using the while loop first

$fileCount = 0
    $exists = 1
    While $exists = 1
        $exists = FileExists(@ScriptDir & "\searches\img" & $fileCount & ".PNG")
        ConsoleWrite(@ScriptDir & "\searches\img" & $fileCount & ".PNG")
        $fileCount = $fileCount + 1
        Sleep(100)
    WEnd

    $fileCount = $fileCount - 1
    $screenShot = _ScreenCapture_Capture("")
    _ScreenCapture_SaveImage(@ScriptDir & "\searches\img" & $fileCount & ".jpg", $screenShot)

this function does not search for the next possible file name instead it just overwrites the file with number initialized with $fileCount

then I did the same thing using do...Until loop

$fileCount = 0
    $exists = 1
    Do
        $exists = FileExists(@ScriptDir & "\searches\img" & $fileCount & ".PNG")
        ConsoleWrite(@ScriptDir & "\searches\img" & $fileCount & ".PNG")
        $fileCount = $fileCount + 1
        Sleep(100)
    Until $exists = 1

    $fileCount = $fileCount - 1
    $screenShot = _ScreenCapture_Capture("")
    _ScreenCapture_SaveImage(@ScriptDir & "\searches\img" & $fileCount & ".jpg", $screenShot)

this ends up being an infinite loop

I cant see the issue here 

i am new to autoit

Share this post


Link to post
Share on other sites
KickStarter15

Why not use FileFindFirstFile() and FileFindNextFile() functions, check with help file.

something like this:

$sFilePath = @ScriptDir & "\"

$hSearch = FileFindFirstFile($sFilePath & "*.png")
$aFileName = FileFindNextFile($hSearch)

 


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
akshatgupta
1 hour ago, KickStarter15 said:

Why not use FileFindFirstFile() and FileFindNextFile() functions, check with help file.

something like this:

$sFilePath = @ScriptDir & "\"

$hSearch = FileFindFirstFile($sFilePath & "*.png")
$aFileName = FileFindNextFile($hSearch)

 

it worked thanks :)

Share this post


Link to post
Share on other sites
KickStarter15

Welc's...^_^


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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

×