How to loop with files in a directory ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rafio
Posts: 41
Joined: 07 Oct 2018, 05:14

How to loop with files in a directory ?

17 Oct 2018, 06:38

I'm trying to batch convert Publisher files to PDF.

First problem, I can't set the initial folder for the FileSelectFolder method:

Code: Select all

startFold := "X:\68-261•Export, Fiches Concours\11•maquettes"
FileSelectFolder strPath, startFold
If strPath = 
{ 
return 
}
msgbox % strPath
Is it because the folder resides on an external disk?

Second, I can't find the way to loop in all .pub files.

Here is my VBA macro to help you understand what I'm trying to do:

Code: Select all

Sub allPDF()

Dim strPath As String
Dim strFile As String
Dim pubApp As Publisher.Application
Dim pubDoc As Publisher.Document

strPath = foldPicker() & "\"
If strPath = "False\" Then Exit Sub

xCount = 0
strFile = Dir(strPath & "*.pub")
Do While strFile <> ""
    thePath = (strPath & strFile)
    theDest = (Left(thePath, (Len(thePath) - 4))) & ".pdf"
    Set pubApp = New Publisher.Application
    Set pubDoc = pubApp.Open(thePath)
    pubApp.ActiveWindow.Visible = False 'execution en arrière-plan
    pubDoc.ExportAsFixedFormat pbFixedFormatTypePDF, theDest
    pubDoc.Close
    xCount = xCount + 1
  strFile = Dir
Loop

MsgBox "L'export est terminé. " & xCount & " fichiers ont été créés."

End Sub
Thanks.
--
Windows 11
AHK 1.1.35.00
Adventure 3.0.4
Rafio
Posts: 41
Joined: 07 Oct 2018, 05:14

Re: How to loop with files in a directory ?

17 Oct 2018, 07:03

Found the solution of my 1st problem:
Just needed to wrap startFold with percent sign.
It's obvious, but not for a beginner in AHK, like me.

Code: Select all

startFold := "X:\68-261•Export, Fiches Concours\11•maquettes"
FileSelectFolder strPath, %startFold%
If strPath = 
{ 
return 
}
msgbox % strPath
--
Windows 11
AHK 1.1.35.00
Adventure 3.0.4
Rafio
Posts: 41
Joined: 07 Oct 2018, 05:14

Re: How to loop with files in a directory ?  Topic is solved

17 Oct 2018, 09:44

I've figured out how to do the loop.

Code: Select all

Loop, Files, %strPath%\*.pub, 
{
    … statements …
} until A_LoopFileName = ""
--
Windows 11
AHK 1.1.35.00
Adventure 3.0.4

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jomaweb, mikeyww and 129 guests