Jump to content

Recommended Posts

Posted

I am very new to using AutoIt, and am hoping it can be used to automate one hopefully straight-forward task.

In my work, I have open a set number of folders on the Windows 10 desktop (typically 21 folders). However, sometimes a restart or software update closes some or all of the windows, and it's a pain to have to reopen and manually reposition them on a semi-frequent basis. What am I looking to do is record the size and position of each open folder. They are currently all launched using a separate explorer.exe instance via a simple .bat file, and I would like to run a simple AutoIt script to open them all and reposition them where they need to be.

I am hoping that is possible, but am unsure how to achieve it. Any pointers gratefully received.

  • Developers
Posted

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

ShellExecute to launch Explorer for a specific folder

WinMove to reposition the Explorer window

ps. manually create a .txt file that contains folder|position|size.  Use _FileReadToArray to read the file and loop thru all entries performing the 2 tasks previously mentioned.

Posted

Hi,

Great stuff.

I have got explorer opening multiple folders working, including their size and position. I have also worked out how to get it to show each folder in List view, which I also needed. I could see that by using variables (folder name, size, position, view) and by then using some kind of array, I could make this much more efficient, so I will now read up on FileReadToArray. Thanks! 🙂

 

Posted (edited)
Run("explorer.exe <folder-name>")
;open the folder
WinWait("[CLASS:CabinetWClass]","",<wait-in-seconds>)
;wait for a few seconds
WinMove("[CLASS:CabinetWClass]", "",<pos1>,<pos2>,<size1>,<size2>)
;move the folder to the stated position and set the size
WinWaitActive("<folder-name>")
;wait for the stated folder to be active
Send("^!<view-type>")
;set the folder view to be the view-type (e.g. 5 for List)

Here's what I've got so far, but I have to admit, looking at FileReadToArray is a bit daunting! The variables I need to use (as indicated above) are the folder name, wait time, position co-ordinates pos1, pos2, then dimensions of the open folder, size1, size2 and the view type, which is likely to always be List (e.g. 5).

Any pointers on what I need to do to get this working for the 21+ folders I need to define would be much appreciated!

Edited by Notechyuser
typo in code
Posted (edited)

Have added a little more to the requirements.

I am also now checking to see if the folder is open already or not. If it is open then it moves it to the correct size and position (regardless of whether it was or not), before continuing to open and move the folder if it wasn't already open. Doing this means that if one or more folders have been accidently closed or moved, you can get them back just by running the script again, and it not opening duplicates of any folders already open.

If WinExists("[TITLE:C:\temp; CLASS:CabinetWClass;]") Then
WinActivate("C:\temp")
WinMove("[CLASS:CabinetWClass]","",1684,8,228,300)
Else
Run("explorer.exe C:\temp")
WinWait("[CLASS:CabinetWClass]","",3)
WinMove("[CLASS:CabinetWClass]","",1684,8,228,300)
WinWaitActive("C:\temp")
Send("^!5")
EndIf

The variables I would need to change for each folder would be (from the above example) C:\temp, 1684, 8, 228, 300, 3, and 5 so I assume these are what would need to be stored in the array text file?

Edited by Notechyuser
typo in main body text
Posted
10 minutes ago, Notechyuser said:

so I assume these are what would need to be stored in the array text file?

Yes exactly. One line per folder.  You can use a coma to separate fields, but I suggest using vertical bar <|> as it is much used in AutoIt.  Also remove unnecessary spaces as they can become a nuisance.

Please tidy your code (Ctrl-T in Scite) to make it more readable.  Thanks.

Posted
10 minutes ago, Nine said:

Yes exactly. One line per folder.  You can use a coma to separate fields, but I suggest using vertical bar <|> as it is much used in AutoIt.  Also remove unnecessary spaces as they can become a nuisance.

Please tidy your code (Ctrl-T in Scite) to make it more readable.  Thanks.

Working backwards, I don't know what you mean in regards to Scite??

I have no idea how to implement the array, or use variables instead of absolute values in my AutoIt script. My knowledge and understanding is really fairly basic. In the old days I would do some kind of for... next loop, but I am really am starting from the ground up on this.

Posted (edited)

Use Scite when modifying your script.  Do not use Notepad or any other editor.  Scite includes a large number of tools to manipulate AutoIt scripts, it is truly a must.  You will need to download the full version of Scite to access all the tools. See here.

Now you can use Notepad to enter your folder information, create a txt file and enter a few lines of folder info. Like this :

C:\temp|1684|8|228|300|3|5

After reading the file with _FileReadToArray, you will indeed use a For...Next loop to display your folders as you already scripted...

Edited by Nine
Posted

I need help in implementing the _FileReadToArray into my code, as none of the examples I've read make any sense to me. I'm not really a programmer, and am finding the help files on the subject extremely confusing.

I know what I need to do in principle, but I don't grasp the correct syntax required in AutoIt to do it. Is anyone willing to take my example code, and show me what needs to be done to it? There seems to be an assumption in many of the help text for AutoIt that you already know what you're doing, and that you understand the given examples, which is definitely not the case for me!

Posted

Also, just thought that it would be useful to have some kind of check that looks for a specific entry in the text file to signify the end of the data. That way, the number of folders defined can presumably be different for each user. I am thinking that if I can get this working, I would compile the program into an exe and supply that and an example array text file to the other people to then define their own folder requirements. Some might need more folders open than I do, and so something like EOL at the end would signify no more entries to be read into the array. Is that possible?

Posted

You do not need to specify anything special inside the text file as _FileReadToArray will take care of that automatically.  In help file :

Quote
$iFlags $FRTA_COUNT (1) - array count in the first element. (default)

Means that in 2D array, $aArray[0][0] contains the number of lines found in the file.

Here the skeleton of the script :

#include <File.au3>

; file should be formatted as described
; C:\temp|1684|8|228|300|3|5

Local $aFolder

_FileReadToArray("You file goes here.txt", $aFolder, Default, "|") ; to create a 2D array
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "File read failed on error " & @error)

For $i = 1 to $aFolder[0][0]
  ; do your things here
  ConsoleWrite($aFolder[$i][0] & @CRLF) ; first element should be folder
  ConsoleWrite($aFolder[$i][1] & @CRLF) ; second element should be x pos
  ConsoleWrite($aFolder[$i][2] & @CRLF) ; third element should be y pos
  ConsoleWrite($aFolder[$i][3] & @CRLF) ; etc.
  ConsoleWrite($aFolder[$i][4] & @CRLF)
  ConsoleWrite($aFolder[$i][5] & @CRLF)
  ConsoleWrite($aFolder[$i][6] & @CRLF)
Next

FYI, it is going to be harder and harder to get help here if you do not make an effort to show you have tried something.  Do not worry if your code is totally wrong, we will not judge you on that, but doing no effort and ordering us to provide code is not going to be pleasant for anyone...

Posted (edited)

Skeleton examples are good, but I should point out (again) that the Help files for AutoIt are not as helpful to a total beginner as you might think,  and it is a hugely daunting task to trawl through dozens or hundreds of example scripts trying to find an example even close to what I am trying to achieve. I am not a programmer by profession, and I have not 'ordered' anyone to do anything in here. This is, after all, a Help & Advice forum. I've been polite, I've asked for pointers, and I've admitted from the start that I don't really know much about any of this. I provided example code to show that I had made a start, and I have been grateful for your responses, as I am grateful for your reply now. I will go through and read up on the various parts of the example you have given, but I still don't grasp how I then incorporate what I have working now (shown earlier) with what you have suggested.

Once the data is read into the array, how would I (for example) express the variable that now contains the folder path that is stored as the first entry in each record and add that into my code? e.g. 

WinActivate("C:\temp")

Is it meant to be ...

WinActivate($aFolder[$i][0])

... and where within the example you have given would I put my original code (with suitable variables inserted)?

Edited by Notechyuser
Added extra info
Posted

I am still struggling to fathom parts of the above?

I understand the #include, and the declaration of the local variable $aFolder. I understand what the _FileReadToArray function is doing, by specifying the exact location of the file (a .txt file that contains the data I have defined for the folders), getting it to detect how many lines of data there are, and then useing the | as a delimiter, it reads my data into a 2D array, which I think is stored starting at $aFolder[0][0], up to $aFolder[21][6], if I have 21 lines of data, with 7 sets of data in each line (for example).

However, what I don't understand from the above is why ConsoleWrite is needed, and how that helps me? Does my previously written code go before or after all those ConsoleWrite statements, and how do I get at the data that is (presumably) now stored in the array and use it in my existing code? Sadly 'do your things here' is not helping me understand this...

Is anyone willing to help me with the latter part of this? I have no further code to post, as none of it has worked and it errors immediately when trying to read in what I thought would be the data from the array (see the example I gave in my previous reply).

Thanks in advance.

Posted

Ok, I see you have worked and you start to understand the basics.  The ConsoleWrite were just there to show you how to access a specific information.  You do not need to have them but it will help you to debug your code if something does not work as expected.  When everything goes very well, you can remove them.

Posted
#include <File.au3>
Local $aFolder

_FileReadToArray ("C:.\folders1.txt", $aFolder, Default, "|")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "File read failed on error " & @error)

For $i = 1 to $aFolder[0][0]
If WinExists("[TITLE:$aFolder[$i][0]; CLASS:CabinetWClass;]") Then
    WinActivate($aFolder[$i][0])
    WinMove("[CLASS:CabinetWClass]", "",$aFolder[$i][1],$aFolder[$i][2],$aFolder[$i][3],$aFolder[$i][4])
Else
    Run("explorer.exe $aFolder[$i][0]")
    WinWait("[CLASS:CabinetWClass]", "", $aFolder[$i][5])
    WinMove("[CLASS:CabinetWClass]", "", $aFolder[$i][1],$aFolder[$i][2],$aFolder[$i][3],$aFolder[$i][4])
    WinWaitActive($aFolder[$i][0])
    Send("^!$aFolder[$i][6]")
EndIf
Next

It defines the first window correctly in terms of size and position, but not in regard to the correct folder. It opens up 'Documents' instead. It then stops, so none of the other defined windows in the folders1.txt file are opened. I assume I'm not inserting the variables from the array correctly?

 

Posted

It is because you include the variable $aFolder[$i][0] inside double quotes, so it is consider as part of the string.  You need to concatenate variables and strings. For example :

WinExists("[TITLE:" & $aFolder[$i][0] & "; CLASS:CabinetWClass;]")

 

Posted (edited)

Ah, I had fiddled with that earlier (putting it in the string quotations) and forgot to put it back to how it was, but I didn't have the correct syntax so it wasn't working anyway.

#include <File.au3>
Local $aFolder

_FileReadToArray ("C:.\folders1.txt", $aFolder, Default, "|")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "File read failed on error " & @error)
For $i = 1 to $aFolder[0][0]
   If WinExists("[TITLE:" & $aFolder[$i][0] & "; CLASS:CabinetWClass;]") Then
      WinActivate($aFolder[$i][0])
      WinMove("[CLASS:CabinetWClass]", "",$aFolder[$i][1],$aFolder[$i][2],$aFolder[$i][3],$aFolder[$i][4])
   Else
      Run("explorer.exe " & $aFolder[$i][0])
      WinWait("[CLASS:CabinetWClass]", "", $aFolder[$i][5])
      WinMove("[CLASS:CabinetWClass]", "", $aFolder[$i][1],$aFolder[$i][2],$aFolder[$i][3],$aFolder[$i][4])
      WinWaitActive($aFolder[$i][0])
      Send("^!" & $aFolder[$i][6])
   EndIf
Next

For some reason the enforced 'List view' on each window (sending a ctrl+shift+5 to the folder window) isn't working, but this otherwise seems to be doing the job now! 🙂

Example data (folders1.txt)

C:\temp|1684|8|228|300|3|5
C:\temp\Linux|1454|8|228|300|3|5
C:\temp\retro|1224|8|228|300|3|5
C:\temp\desktop stuff|996|8|228|300|3|5

Edited by Notechyuser
Added example data
Posted

Sorry, my mistake.

Send("^!" & $aFolder[$i][6])

It's Ctrl + Alt + 5 to change to List view in Windows, not Ctrl + Shift + 5, so I have the correct keypress in the AutoIt script, but it isn't working. I'm guessing that it won't send a keypress using a variable, or I have the wrong syntax.

 

 

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...