Jump to content

Making a script that will loop a function until a directory is empty


Recommended Posts

I have a script that resizes images so that they're usable on an intranet site. Once the image is resized it's copied to a finished directory. I'd like to have the script loop until the initial directory is empty. I've see the DirGetSize be mentioned but I'm not quite sure how to implement it in the use I'm looking for.

Here's my code so far:

Opt('MouseCoordMode',0)
Opt("WinTitleMatchMode", 2)

#region ---Au3Recorder generated code Start (v3.3.7.0) ---

#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc

#endregion --- Internal functions Au3Recorder End ---

Do

Run('C:\WINDOWS\system32\mspaint.exe')
_WinWaitActivate("untitled - Paint","")
MouseClick("left",12,28,1)
MouseClick("left",30,70,1)
_WinWaitActivate("Open","")
MouseClick("left",59,163,1)
MouseClick("left",127,120,1)
MouseClick("left",504,364,1)
MouseClick("left",456,47,1)
MouseClick("left",476,132,1)
MouseClick("left",331,69,1)
Sleep(500)
MouseClick("left",331,69,1)
MouseMove(143,85)
MouseDown("left")
MouseMove(142,85)
MouseUp("left")
MouseClick("left",514,359,1)
_WinWaitActivate("Paint","")
MouseClick("left",111,33,1)
MouseClick("left",118,68,1)
_WinWaitActivate("Stretch and Skew","")
Send("??{TAB}??")
MouseClick("left",306,42,1)
_WinWaitActivate("Paint","")
MouseClick("left",15,33,1)
MouseClick("left",31,102,1)
_WinWaitActivate("Save As","")
MouseClick("left",135,70,1)
MouseClick("left",507,360,1)
MouseClick("left",507,360,1)
_WinWaitActivate("Paint","")
MouseClick("left",16,32,1)
MouseClick("left",55,360,1)
#endregion --- Au3Recorder generated code End ---

Until(
Link to comment
Share on other sites

  • Moderators

ChrisLanders,

Welcome to the AutoIt forum. :)

I would use FileListToArray to get an array of all the files in the folder. You can then loop through the list and use ShellExecute to open them into Paint (assuming that is the default app for their file type) - or Run as you already do but using the filename as a parameter. You run the loop for as many times as you have files - and then you should have actioned all the files. :)

I would also look at actioning the various Paint menus and dialogs directly using AutoIt rather than the messy (and very unreliable) MouseClick method you are using at the moment - after all that is what it is designed to do. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
 Share

  • Recently Browsing   0 members

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