Selecting multiple files and opening it with one program

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jollyjoe
Posts: 45
Joined: 13 Feb 2021, 18:51

Selecting multiple files and opening it with one program

06 May 2024, 11:46

I am trying to automate a task for hundreds of files in a lot of folders. I am on the last step which is to select all the .DDS files and drag them into the app called RFSRePack.exe.

I am stuck in this last part since I dont know how to simulate selecting all files and dragging them to a program (Gif posted below)
sample.gif
sample.gif (97.52 KiB) Viewed 335 times
Here is my code, The part in which I need help in is the label called "rftrfs", the last label. Right now all it does is it opens each file with RFSRePack, I need to open ALL files at once (Like simulating select all and drag) with RFSRePack.

Code: Select all

SetWorkingDir, %A_Desktop%\RFS Unpacker

Gui, New
Gui Add, Button, w180 grfsrft, RFS to RFT
Gui Add, Button, w180 grftdds vrftdds, RFT to DDS
Gui Add, Button, w180 gddsrft vddsrft, DDS to RFT
Gui Add, Button, w180 grftrfs vrftrfs, RFT to RFS
Gui, Show, w200
Return
rfsrft:
Loop, Files, F:\Games\RF Online Global\Character\Monster\Tex\*.RFS
    {
        _folder := Trim(A_LoopFileName, ".RFS")
        FileCreateDir, %_folder%
        FileCopy, F:\Games\RF Online Global\Character\Monster\Tex\%A_LoopFileName%, %_folder%
        SetWorkingDir, %A_Desktop%\RFS Unpacker\%_folder%
        FileCopy, %A_Desktop%\RFS Unpacker\RFSUnPack.exe, %A_Desktop%\RFS Unpacker\%_folder%
        RunWait, RFSUnPack.exe %A_LoopFileName%
        SetWorkingDir, %A_Desktop%\RFS Unpacker
        FileDelete, %_folder%\RFSUnPack.exe
        FileDelete, %_folder%\%A_LoopFileName%
    } 
Return

rftdds:
Loop, Files, *.*, D
    {
        FileCopy, RFT-DDS.exe, %A_LoopFileName%
        SetWorkingDir, %A_LoopFileName%
        Loop, Files, *.*
            {
                if (A_LoopFileExt = "RFT") {
                    GuiControl, Text, rftdds, %A_LoopFileName%
                    RunWait, RFT-DDS.exe %A_LoopFileName%
                    FileDelete, %A_LoopFileName%
                }
            }
        SetWorkingDir, %A_Desktop%\RFS Unpacker
        If (A_LoopFileExt = "ahk" OR A_LoopFileExt = "exe" OR A_LoopFileExt = "RFS" OR A_LoopFileExt = "RFT" OR A_LoopFileExt = "DDS" ) {
        } else {
            GuiControl, Text, rftdds, %A_LoopFileName%
        }
    }
Return

ddsrft:
Loop, Files, *.*, D
    {
        FileCopy, RFT-DDS.exe, %A_LoopFileName%
        SetWorkingDir, %A_LoopFileName%
        Loop, Files, *.*
            {
                if (A_LoopFileExt = "DDS") {
                    GuiControl, Text, ddsrft, %A_LoopFileName%
                    RunWait, RFT-DDS.exe %A_LoopFileName%
                    FileDelete, %A_LoopFileName%
                }
            }
        FileDelete, RFT-DDS.exe
        SetWorkingDir, %A_Desktop%\RFS Unpacker
        If (A_LoopFileExt = "ahk" OR A_LoopFileExt = "exe" OR A_LoopFileExt = "RFS" OR A_LoopFileExt = "RFT" OR A_LoopFileExt = "DDS" ) {
        } else {
            GuiControl, Text, ddsrft, %A_LoopFileName%
        }
    }
Return

rftrfs:
Loop, Files, *.*, D
    {
        FileCopy, RFSRePack.exe, %A_LoopFileName%
        SetWorkingDir, %A_LoopFileName%
        Loop, Files, *.*
            {
                if (A_LoopFileExt = "RFT") {
                    GuiControl, Text, ddsrft, %A_LoopFileName%
                    RunWait, RFSRePack.exe %A_LoopFileName%
                    FileDelete, %A_LoopFileName%
                }
            }
        FileDelete, RFSRePack.exe
        SetWorkingDir, %A_Desktop%\RFS Unpacker
        If (A_LoopFileExt = "ahk" OR A_LoopFileExt = "exe" OR A_LoopFileExt = "RFS" OR A_LoopFileExt = "RFT" OR A_LoopFileExt = "DDS" ) {
        } else {
            GuiControl, Text, ddsrft, %A_LoopFileName%
        }
    }
Return

GuiClose:
ExitApp
ShatterCoder
Posts: 84
Joined: 06 Oct 2016, 15:57

Re: Selecting multiple files and opening it with one program

06 May 2024, 16:08

to pass a list of files to an executable all you need to do is put a space between each file name (note: if the path to the file contains a space it must be enclosed in quotes for this very reason). A simple way to achieve this would be to change your rftrfs label so that rather than the runwait on line 77 you could simply add the file to a list something like:

Code: Select all

rftrfs:
Loop, Files, *.*, D
    {
        FileCopy, RFSRePack.exe, %A_LoopFileName%
        SetWorkingDir, %A_LoopFileName%
        File_List := ""
        File_Arr := []
        Loop, Files, *.*
            {
                if (A_LoopFileExt = "RFT") {
                    GuiControl, Text, ddsrft, %A_LoopFileName%
                    File_List .= """" A_LoopFileName """ " ;all the quotes here are just to ensure that the file names are enclosed in quotes 
                    File_Arr.push(A_LoopFileName) ;add the filename to an array so we can delete the files outside of the loop
                }
            }

        RunWait, RFSRePack.exe %File_List% ;move the command out of the loop
        ;then delete the files
        for k, v in File_Arr
        {
           FileDelete, % v
        }
        FileDelete, RFSRePack.exe
        SetWorkingDir, %A_Desktop%\RFS Unpacker
        If (A_LoopFileExt = "ahk" OR A_LoopFileExt = "exe" OR A_LoopFileExt = "RFS" OR A_LoopFileExt = "RFT" OR A_LoopFileExt = "DDS" ) {
        } else {
            GuiControl, Text, ddsrft, %A_LoopFileName%
        }
    }
Return
I would encourage you to test cautiously and non destructively. perhaps just comment out all the FileDelete command the first time through and add a few message boxes to verify that it is doing what you want. But that should be essentially what you are looking for.
ShatterCoder
Posts: 84
Joined: 06 Oct 2016, 15:57

Re: Selecting multiple files and opening it with one program

06 May 2024, 16:18

One additional note. I saw some documentation that suggests that there may be a limit of 9 files in the list at a time. It seems the limit has to do with how the batch / cmd interpreter parses it out as %%1 - %%9 (with no double digit numbers being possible). It is unclear if this limitation is exclusively for Batch files, or if it applies to all command line parameters. I know it can be achieved by drag and drop like you said, so there is clearly a workaround for it if there is a limitation there. Let me know if you run into trouble with that and we can see what we come up with for a solution.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, peter_ahk and 92 guests