Scan barcode or QR code to open matching folder

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
seasonalaffect
Posts: 2
Joined: 17 Sep 2021, 17:37

Scan barcode or QR code to open matching folder

Post by seasonalaffect » 21 Sep 2021, 15:27

I have a similar goal to what is described in this thread: https://autohotkey.com/board/topic/102329-scan-barcodeopen-file/

I'd like to scan a QR code or barcode with a scanner, which then opens a folder with the matching order number.

Currently, I'm trying a slightly modified version of the script in the linked thread above. In the GUI, I scan a QR or barcode, and the folder matching the "%pdfname%" opens up. This seems to work well, but it doesn't seem to search any subfolders. Many folders I'm looking for are stored 2 to 4 subfolders inside the "E:\Printer PC Shared Folder\". How can I edit this to search all subfolders?

Code: Select all

SetTitleMatchMode 2
Gui, +alwaysontop            ;keeps the gui on top level
Gui, Add, Edit , w200 vpdfname,
Gui, Add, Button, gopenpdf default , OPEN
Gui, show ,, scantopdf            ;give name to gui for later reference

return

openpdf:
Gui,Submit,Nohide
If (pdfname = "" )
{
ControlFocus
return
}

Loop, Files, E:\Printer PC Shared Folder\*, D
    If A_LoopFileName contains %pdfname%
          Run %A_LoopFileFullPath%
      WinActivate

Guicontrol,,pdfname,            ;makes the edit box blank
sleep 4000                ;wait 4 seconds for pdf to load
WinActivate,scantopdf            ;then reactivate the gui window
return

Exit:
GuiClose:
ExitApp
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Scan barcode or QR code to open matching folder

Post by Smile_ » 21 Sep 2021, 16:11

Use R mode in your loop command like this Loop, Files, E:\Printer PC Shared Folder\*, D R
seasonalaffect
Posts: 2
Joined: 17 Sep 2021, 17:37

Re: Scan barcode or QR code to open matching folder

Post by seasonalaffect » 27 Sep 2021, 11:19

Smile_ wrote:
21 Sep 2021, 16:11
Use R mode in your loop command like this Loop, Files, E:\Printer PC Shared Folder\*, D R
This worked, thank you!

Because this searches quite a large directory, it takes a while to return results. Is it possible to limit the search to a list of specific folders in the directory? Possibly using a list of folder paths in a text file or something like that? If it's easier to include a list in the actual code that would work too. I just may need to update the list periodically.
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Scan barcode or QR code to open matching folder

Post by Smile_ » 27 Sep 2021, 13:28

Yeah here is some explained examples
1 - Including the folders in your script
Define them using a delimiter (will be used after for parsing them). For example using a pipe as delimiter

Code: Select all

FoldersList := "C:\Folder1"
             . "|C:\Folder2\Folder3"
             . "|C:\Folder4\Folder"
; This is equivalent to: FoldersList := "C:\Folder1|C:\Folder2\Folder3|C:\Folder4\Folder"
Then search these folders ( FoldersList ) using another loop command containing your previous loop command. For example

Code: Select all

Loop, Parse, FoldersList, % "|"
{
    Loop, Files, % A_LoopField "\*", D R
    {
        If InStr(A_LoopFileName, pdfname)
            Run, % A_LoopFileFullPath
    }
}
2 - Using external file
Lets suppose we have a text file named FolderLIst.txt containing these 3 lines

Code: Select all

C:\Folder1
C:\Folder2\Folder3
C:\Folder4\Folder
What you have to do is to read it using FileRead or any other possible method
FileRead, FoldersList, FoldersList.txt

Then the rest is the same.

HIH
Post Reply

Return to “Ask for Help (v1)”