samsphsw Posted June 20, 2017 Posted June 20, 2017 Hey, Just started learning AutoIt couple weeks ago, so don't laugh too hard on my script please I'm trying to have the script to grab every PDF file in a certain folder, and convert it into Word using a software called "Abbyy Fine Reader". However, I could not get the exact directory of each pdf file and input it into the software. This is what i have so far: #include <IE.au3> #include <Array.au3> #include <File.au3> Global $dir = "C:\Work\ToDo" AutoItSetOption('MouseCoordMode', 0) $search = FileFindFirstFile($dir) If $search = -1 Then Else Global $PdfFiles = _FileListToArray($dir, '*.pdf', 1) For $File in $PdfFiles Run("C:\Program Files (x86)\ABBYY FineReader 14\FineReader.exe") WinWait("ABBYY FineReader 14 Corporate") ControlClick('ABBYY FineReader 14 Corporate', '', 'Button27') WinWait('Select Files to Convert to PDF') ControlClick('Select Files to Convert to PDF', '', 'Edit1') Send($File) ;~ This is where I am having trouble WinWait('ABBYY FineReader 14 Corporate') ControlClick('ABBYY FineReader 14 Corporate', '', 'Button49') WinWait('Save document as') ControlClick('Save document as', '', 'Edit1') Send($dir) Send("{ENTER}") ControlClick('Save document as', '', 'Button5') WinWait("[CLASS:OpusApp]") WinClose("[CLASS:OpusApp]") Next EndIf
Moderators JLogan3o13 Posted June 20, 2017 Moderators Posted June 20, 2017 (edited) @samsphsw welcome to the forum. If you set the last parameter in _FileListToArray to True it will return the full path to the file for you, rather than just the relative. Edited June 20, 2017 by JLogan3o13 "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!
samsphsw Posted June 21, 2017 Author Posted June 21, 2017 Hi JLogan3o13, Thanks for the warm welcome. I tried to include the TRUE argument but still ran into trouble with this code. I tried to place a msgbox to see if the dir is correctly extracted. See screenshot below:
Floops Posted June 21, 2017 Posted June 21, 2017 (edited) MsgBox needs at least 3 arguments. First you need the flag which changes the type and buttons of the MsgBox, use 0 for now. The second argument is the title of the MsgBox, you can leave it empty if you want but you still need to include it (pass "" for no title) Third argument is the text of the MsgBox in your case $file. In your case the MsgBox should look somewhat like this. MsgBox(0, "", $File) Edited June 21, 2017 by Floops
samsphsw Posted June 23, 2017 Author Posted June 23, 2017 Hi Floops, Thanks for the tips, but my key problem here is the For Function: Global $PdfFiles = _FileListToArray($dir, '*.pdf', 1, True) For $File in $PdfFiles $File is not returning the full directory of the PDFs. Did I use it incorrectly?
Floops Posted June 23, 2017 Posted June 23, 2017 Hmm, the syntax looks correct, when using that code I get full paths. Can you try a different folder/mask and see if it works then?
benners Posted June 23, 2017 Posted June 23, 2017 (edited) 4 hours ago, samsphsw said: $File is not returning the full directory of the PDFs. Did I use it incorrectly? $PdfFiles[0] = Number of Files\Folders returned so the first pdf path in your loop will be a number, is that what you are seeing and is making you think your code is wrong?. If so you can use For $i = 1 to $PdfFiles[0] Edited June 23, 2017 by benners
samsphsw Posted June 26, 2017 Author Posted June 26, 2017 I figured it out!!! LOL, was using the For function incorrectly, so I should be referring to the variables in the array as $PdfFiles[$i] instead of just $i. Thank you all again for the help!!! Here's my completed code: For $i = 1 To $FileList[0] Run("C:\Program Files (x86)\ABBYY FineReader 14\FineReader.exe") WinWait("ABBYY FineReader 14 Standard") ControlClick('ABBYY FineReader 14 Standard', '', 'Button27') WinWait('Select Files to Convert to Microsoft Word') ControlSetText("Select Files to Convert to Microsoft Word","","Edit1", $FileList[$i]) ControlClick('Select Files to Convert to Microsoft Word', '', 'Button1') WinWait('ABBYY FineReader 14 Standard') ControlClick('ABBYY FineReader 14 Standard', '', 'Button49') WinWait('Save document as') ControlClick('Save document as', '', 'Edit1') ControlSetText('Save document as', '', 'Edit1', _RemoveFileExt($FileList[$i])&".docx") ControlClick('Save document as', '', 'Button5') WinWait("[CLASS:OpusApp]") WinClose("[CLASS:OpusApp]") Next
benners Posted June 26, 2017 Posted June 26, 2017 3 hours ago, samsphsw said: I figured it out!!! LOL, was using the For function incorrectly, so I should be referring to the variables in the array as $PdfFiles[$i] instead of just $i. Well if you'd have read my post, You'd have figured it out a lot sooner
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now