Jump to content

Grabbing file directory Question


Recommended Posts

Hey,

Just started learning AutoIt couple weeks ago, so don't laugh too hard on my script please :lol:

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

 

Link to comment
Share on other sites

  • Moderators

@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 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!

Link to comment
Share on other sites

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:

 

 

Untitled.png

Link to comment
Share on other sites

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 by Floops
Link to comment
Share on other sites

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 by benners
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 :P

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