Jump to content

Recommended Posts

Posted

So, I haven't programmed in years. AutoIt has brought back my interest. I am working to automate many processes. The current process is opening PDFs and converting them to Excel. I don't want the Array to worry about the file name, nor the amount of files in the folder. I built many small macros with the recorder. I want to run these macros on one file, then loop and do the reset in the folder. It works to do one file, however it will not move to the next file. Ive tinkered around with $i + 1 etc, but obviously don't have it in the proper location. I have been researching this site, other sites, and the help files. I find many options, but vast the variety of options, leave me with code that does not increment to the next file. I could delete the first file so that the next file is the "new first file" when it loops, however I am not able to capture the file name so that the code knows the file to remove. Then I thought, maybe I ought to not delete anything, and just get it working so that it moves to the next file. Ive looked at FileNextFile etc, but have had a bunch of issues. So, I figured I would ask the pros. I am most likely over-complicating it, but I have learned a lot about autoit in the process. Please someone throw me a bone here.....

Be nice, and thanks in advance :-)

 

#include <file.au3>
#include <array.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

;==========================================
$extension    = "pdf"
;==========================================

$monarch = "C:\Program Files\Datawatch Monarch 13\DPS\DWDataPrepStudio.exe"
$path = "C:\PDF"
$choosePDF = "C:\Macros\3_ChoosePDF.exe"
$chooseColumns = "C:\Macros\4_ChooseColumns.exe"
$chooseMemberColumn = "C:\Macros\5_ChooseMemberColumn.exe"
$dataPrep = "C:\Macros\6_DataPrepPreviewLoadTables.exe"
$nulls = "C:\Macros\7_Nulls.exe"
$export = "C:\Macros\8_Export.exe"
$closeMonarch = "C:\Macros\9_CloseMonarch.exe"
$deleteFirstPdfFile = "C:\Macros\10_DeleteFirstPdfFile.exe"

;==========================================

; ########################################
;~ Example()  ; just trying something
;~ Func Example()
;~
;~ While $FileArray <> 0
;~ _ArrayPop($FileArray)
;~ _ArrayDisplay($FileArray)
;~ EndFunc
; ########################################

$FileArray = _FileListToArray($path, "*." & $extension,1) ; As long as a file exists in C:\PDF - get the list of files

For $i = 1 To $FileArray[0]

Run($monarch  & ' "' & $path &  $FileArray[$i] -1 & '"') ;Runs Monarch
Sleep(8000)
ProcessExists($monarch)

Run($choosePDF) ;Runs $choosePDF
ProcessWaitClose($choosePDF)

Run($chooseColumns)
Sleep(5000)
ProcessWaitClose($chooseColumns)

RunWait($chooseMemberColumn)
Sleep(5000)
ProcessWaitClose($chooseMemberColumn)

RunWait($dataPrep)
Sleep(5000)
ProcessWaitClose($dataPrep)

RunWait($nulls)
Sleep(5000)
ProcessWaitClose($nulls)

RunWait($export)
Sleep(5000)
ProcessWaitClose($export)

Run($closeMonarch)
Sleep(5000)
ProcessWaitClose($closeMonarch)

RunWait($deleteFirstPdfFile)
Sleep(5000)
ProcessWaitClose($deleteFirstPdfFile)

ProcessWaitClose($monarch)
Sleep(5000)

Next

 

  • Moderators
Posted

First question, once you do your _FileListToArray line, does an _ArrayDisplay command show you what you would expect (i.e. the full path name of all the files in the directory)?

Secondly, on your run line:

Run($monarch  & ' "' & $path &  $FileArray[$i] -1 & '"') ;Runs Monarch

Have you output that to the Console to confirm you're not missing any /'s?

 

Beyond those two simple checks, and if the process is successful all the way through your first For iteration, you're going to have to explain more about what these embedded executables are doing. The problem may lay with one of them, rather than your main script.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Thank you for the response!

1. An _ArrayDisplay does give me the list of the array. If I add or remove files, the array does adjust correctly.

=============

This is what I currently get when using _ArrayDisplay:

Row|Col 0
[0]|6
[1]|CAPT3662010.pdf
[2]|CAPT3662011.pdf
[3]|CAPT3662012.pdf
[4]|CAPT3662013.pdf
[5]|CAPT3662014.pdf
[6]|CAPT3662015not.pdf

==============

****Every time I run the original code, the code always picks the CAPT3662015not.pdf file. I need it to move to the next file each time it loops. It currently loops but never moves from the last file.

2. Output to Console passes successfully.

3. The process is successful all the way through for the first file that is chosen. As you mentioned maybe the issue is with my embedded .exes. I am choosing the file with a recorded macro, called (choosepdf.exe). I just recorded myself choosing a file in C:\PDF. So I was thinking to remove that file, so the next time I loop through, it will pick the next file. I would like know how to choose the file without a recorded macro. FileOpen doesnt really double click and my most frustrating issue is that it does not change files.

4. What is a better way to choose a file and loop through that folder? I am looping through all of the processes with one file (my choosepdf.exe picks the first file in the list). But I need to loop through that folder.

****Heres the code for the choosepdf.exe file. Maybe this is the culprit. Its just a recorded macro...:

AutoItSetOption("MouseCoordMode", 0)

;WinWait("Untitled") ;waits for the window to open
WinActivate("Untitled") ;activates the window
MouseClick("primary", 464, 524, 1, 0) ;

MouseClick("primary", 363, 583, 1, 0)

MouseClick("primary", 537,99, 1, 0) ;clicks on address bar
Send("C:\PDF")
MouseClick("Primary", 493, 191, 2, 0) ;chooses the first file in the list by double-clicking

 

 

 

 

 

 

Posted

What happens if you try something like:

#include <File.au3>

Opt('ExpandVarStrings', 1)

Global $hMonarch = "C:\Program Files\Datawatch Monarch 13\DPS\DWDataPrepStudio.exe"
Global $sPath = "C:\PDF"
;~ ... <rest of your code here>

Global $aFileList = _FileListToArrayRec($sPath, '*.pdf', 1, 1, 0, 2)
If @error Then Exit

For $i = 1 To $aFileList[0]
    Run('"$hMonarch$" "' & $aFileList[$i] & '"');Runs Monarch
;~ ... <rest of your code here>
Next

 

Posted
  On 12/29/2016 at 4:01 PM, DarylDixon said:

This is what I currently get when using _ArrayDisplay:

Row|Col 0
[0]|6
[1]|CAPT3662010.pdf
[2]|CAPT3662011.pdf
[3]|CAPT3662012.pdf
[4]|CAPT3662013.pdf
[5]|CAPT3662014.pdf
[6]|CAPT3662015not.pdf

==============

****Every time I run the original code, the code always picks the CAPT3662015not.pdf file. I need it to move to the next file each time it loops. It currently loops but never moves from the last file.

Expand  

Why the -1?

Run($monarch  & ' "' & $path &  $FileArray[$i] -1 & '"')

Also

Line

_FileListToArray($path, "*." & $extension,1)

could simply be:

_FileListToArray($path, "*.pdf", 1)

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

  • 3 weeks later...
Posted

Thanks to everyone that commented.

To give you an update, I realized I am looping all of my steps so that they repeat, but not looping inside of the folder so that it applies to each file.

I ended up adding a script so that after the first file is complete, it is deleted. When the scripts start over, it will pick the new first file. Cheesy, I know...its working though. I would like to get it to work properly. So if anyone has a link to an example of looping through several scripts/functions, AND looping through .pdf/.xls files in a folder....that'd be grrreaaattt.  If I recall correctly from all my old college courses, that would be a nested loop?

I appreciate all of the suggestions. Most of the code posted before came from examples, so that would be why I used the syntax, that I did, in my code. Once I get this working on my PC, nicely, I will look to fine tune the code.

My New issues are:

1. Nested Loops (Same issue as above)

2. Getting the macros and clicks to work on someone else's computer! Becaussseeee it isn't working else where.....(Window Size an issue?). What are your experiences and fixes for this issue? ControlClick vs Send the issue when running code on another pc? We both remote into a Virtual PC and we are both running this code on that virtual pc, not our own pc. Is it screen size??

3. Reading text from a single cell in an already open excel file, and do an if statement off of the text in that one cell. If Cell A1 = "member" do this, else do this...

I know, I know, post a new question. I will search the site before I start a new feed. But if someone has the answers to a nested loop, post below, or send me a message please! You would help me greatly!

Thanks again!

  • Moderators
Posted

DarylDixon,

  Quote

looping through .pdf/.xls files in a folder

Expand  

This post of mine from yesterday might be of interest.

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:

  Reveal hidden contents

 

Posted (edited)

@DarylDixon - Have you looked at Monarchs Built-in Automation?  If you were to build a Model you could then use the command line options within Monarch to apply these models to your files http://docs.datawatch.com/monarch/commandline_guide/Datawatch_Monarch_Command_Line_User_Guide.pdf

This would be the most resilient way for managing your documents rather than send keys and mouse movments.

 

 

Edited by Subz
Accidental Post

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