FileSelectFile Multi-select Option Issue. Please help! Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 19:18

Hello everyone
I was wondering if there is someone out there could help me with my issue.
I'm trying to SplitPath multiple files one by one with no success so far. When I do it one file at a time it works.
Any help is appreciated!
Thank you all in advance.

Code: Select all

; Selecting one file at a time works
FileSelectFile, SourceFile, 3, %A_WorkingDir%, SourceFile
if SourceFile = 
return
SplitPath, SourceFile, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt

; Selecting multiple files doesn't work
FileSelectFile, SourceFile, M, %A_WorkingDir%, SourceFile
if SourceFile = 
return
Loop, parse, SourceFiles, `n
if A_Index > 1
/*
Tried
SplitPath, SourceFile, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt	; doesn't recall anything
SplitPath, %SourceFile%, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt	; the variable is blank 
SplitPath, A_LoopField, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt	; returning only last selected file
SplitPath, %A_LoopField%, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt	; returning an illegal character 
*/
nullDC := %HOME%\nullDC.exe -config nullDC_GUI:Fullscreen=1 -config nullDC:Emulator.Autostart=1 -config ImageReader:LoadDefaultImage=1 -config ImageReader:DefaultImage="%SourceFileName%"
Dolphin := %HOME%\Dolphin.exe -e "%SourceFileName%"
PPSSPP := %HOME%\PPSSPPWindows.exe "%SourceFileName%"
pcsx2 := %HOME%\pcsx2.exe "%SourceFileName%"

if SourceFileDir contains nullDC		; not sure if it's possible to make it more dynamic instead of repeating the function
{
	FileDelete, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - nullDC.bat
	FileAppend, %nullDC%, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - nullDC.bat
}

if SourceFileDir contains Dolphin
{
	FileDelete, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - Dolphin.bat
	FileAppend, %Dolphin%, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - Dolphin.bat
}

if SourceFileDir contains PPSSPP
{
	FileDelete, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - PPSSPP.bat
	FileAppend, %PPSSPP%, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - PPSSPP.bat
}

if SourceFileDir contains pcsx2
{
	FileDelete, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - pcsx2.bat
	FileAppend, %pcsx2%, %A_WorkingDir%\%LogDir%\%SourceFileNoExt% - pcsx2.bat
}
Last edited by gamesguy383 on 11 Feb 2018, 20:03, edited 2 times in total.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 19:34

A_Index and A_LoopField don't mean anything without a loop. It looks like you tried to follow the example in the documentation, but you left out the key part: the loop.
You need a parsing loop or use StringSplit/StrSplit() to break the SourceFile variable up into the various file names before you can apply SplitPath to the pieces it gets split up into. To understand what's in SourceFile, put MsgBox, %SourceFile% immediately after your FileSelectFile command.

Edit: It looks like you edited it and added the loop command while I was typing the response.
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 19:47

To check if it is returning anything I use "MsgBox %SourceFileName%" at the end. Is that wrong?
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 19:53

It's not wrong, but I suggested seeing the contents of SourceFile first so you understand what it is you're trying to split. You can check how it split it at the end like you suggest.

Rather than just trying a bunch of different combinations of SplitPath, look at the command definition and decide what belongs in which parameter.

SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]
The first parameter is the variable name (so don't put % around it) that contains the path you're looking to split. Since it's the result of the parsing loop, that would be A_LoopField. SourceFile is a variable, but it doesn't contain a path, it contains several lines of text that need to be split into individual paths before you can use SplitPath, which is why that wouldn't be what you use here.
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:06

Sorry i keep editing the original code. Now you can see the purpose for the SplitPath.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:21

You should post changes to the code in new posts. It loses the thread of the conversation for anyone else viewing it and trying to understand why certain responses were made.

Your string assignments to nullDC and such are not correct. If you want to keep it as expression syntax (with the := assignment operator), you need quotes around the whole string, and you'll need to escape the quotation marks you want to include with extra quotation marks. If you want to use legacy syntax (with the = assignment operator), you leave it without the quotes around the whole string, but then you'll have to deal with the % signs so it doesn't for example replace %HOME% with the value of the variable HOME (which is nothing). You can use MsgBox, %nullDC%, etc., on any of these to see where it's going wrong with either method and what you have to fix.
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:36

You're absolutely right! My apologies for the editing once again. I'm new to this, so I thank you for your patience. It seems that when I don't take my time I make mistakes.

Code: Select all

nullDC := %HOME%\nullDC.exe -config nullDC_GUI:Fullscreen=1 -config nullDC:Emulator.Autostart=1 -config ImageReader:LoadDefaultImage=1 -config ImageReader:DefaultImage="%SourceFileName%"
Dolphin := %HOME%\Dolphin.exe -e "%SourceFileName%"
PPSSPP := %HOME%\PPSSPPWindows.exe "%SourceFileName%"
pcsx2 := %HOME%\pcsx2.exe "%SourceFileName%"

; should be
nullDC = %HOME%\nullDC.exe -config nullDC_GUI:Fullscreen=1 -config nullDC:Emulator.Autostart=1 -config ImageReader:LoadDefaultImage=1 -config ImageReader:DefaultImage="%SourceFileName%"
Dolphin = %HOME%\Dolphin.exe -e "%SourceFileName%"
PPSSPP = %HOME%\PPSSPPWindows.exe "%SourceFileName%"
pcsx2 = %HOME%\pcsx2.exe "%SourceFileName%"
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:46

Another question is: is it possible to make the filter into an expression? something like:

Code: Select all

if SourceFiles in %A_WorkingDir%\nullDC
extensions := *.iso
if SourceFiles in %A_WorkingDir%\Dolphin
extensions := *.bin
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:48

So I guess you have a variable named HOME in your script to which you assigned a string of text. I thought you were wanting the exact text "%HOME%" in your string because you're using a Windows environment variable.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:53

gamesguy383 wrote:Another question is: is it possible to make the filter into an expression? something like:

Code: Select all

if SourceFiles in %A_WorkingDir%\nullDC
extensions := *.iso
if SourceFiles in %A_WorkingDir%\Dolphin
extensions := *.bin
I don't know what you're asking. Are you wanting to find out if any of the file paths contained in SourceFiles start with %A_WorkingDir%\nullDC ?
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:54

%HOME% is necessary for the other script. The value is there and it picks it up OK.
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 20:57

if I pick a directory nullDC the filter or extensions to be visible for FileSelectFile only ISO
if I pick a directory Dolphin the filter or extensions to be visible for FileSelectFile only BIN
and so on
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 21:19

I guess you want to do this:

Code: Select all

if InStr(SourceFiles, A_WorkingDir "\nullDC")
	extensions := "*.iso"
if InStr(SourceFiles, A_WorkingDir "\Dolphin")
	extensions := "*.bin"
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 21:43

Not sure if it's possible to do that. If you put the expression before FileSelectFile, you can't pick up the "SourceFile". If you put the expression after FileSelectFile, it will be too late for the %extensions%.

Code: Select all

if InStr(SourceFiles, A_WorkingDir "\nullDC")
	extensions := "*.iso"
if InStr(SourceFiles, A_WorkingDir "\Dolphin")
	extensions := "*.bin"
FileSelectFile, SourceFile, 3, %A_WorkingDir%, SourceFile, %extensions% ; should pick up %extensions% but "if SourceFiles" might be early? no value there yet?
if SourceFile = 
return
SplitPath, SourceFile, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 21:57

I don't understand what you're trying to do. You want to change the filter as you change directories while the file selector box is open? You cant do that.
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 22:02

Yes! That's what I was trying to do.
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 22:07

Any ideas how I could fix this? Or what I'm missing? To perform my later functions.

Code: Select all

FileSelectFile, SourceFile, M, %A_WorkingDir%, SourceFile
if SourceFile = 
return
Loop, parse, SourceFiles, `n
if A_Index > 1
SplitPath, A_LoopField, SourceFileName, SourceFileDir, SourceFileExt, SourceFileNoExt
gamesguy383
Posts: 21
Joined: 09 Feb 2018, 02:10

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 22:12

What if I set the attributes to "read-only" for the files I don't want to see. You think there is an expression I could use then? I remember seeing something like that
Last edited by gamesguy383 on 11 Feb 2018, 22:19, edited 1 time in total.
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: FileSelectFile Multi-select Option Issue. Please help!

11 Feb 2018, 22:17

I don't know what you're trying to do by selecting multiple files but then just having one set of variables for the outputs of SplitPath. If you're trying to operate on all the files, you need to be assigning the outputs to array elements. Then later you need loops to operate on each set of variables.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wilkster and 287 guests