samsphsw

Grabbing file directory Question

9 posts in this topic

#1 ·  Posted

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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Floops

Share this post


Link to post
Share on other sites

#5 ·  Posted

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?

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

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?

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by benners

Share this post


Link to post
Share on other sites

#8 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

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

Share this post


Link to post
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