FileSelecFile on the PPC won't start in a specified directory, look more than two folders deep in to the file tree, or look in folders other than My Doucments and the Storage Card. So with some input from a_h_k, I made a Function to replace FileSelectFile for use on PPC's that does all three.
Code:
Getfile(CurDir="\",Ext="*.*",Title="Select a File",Btn="Open") {
CurExt:=Ext
RetValue=Canceled
SingleClick=0 ;if 1 tap on file to open
;File types you want special names for
ahk= Autohotkey script (*.ahk)
txt= Text File (*.txt)
ini= Ini File (*.ini)
Global FileChoice
Global AddressBar
Global ExtDDl
lExt:=SubStr(Ext,3)
If (Ext="*.*")
extList = All files (*.*)||
Else If (%lExt%="")
extList = %Ext%||All files (*.*)
Else
extList:=%lExt% "||All files (*.*)"
Gui, 99:Add, Edit, x2 y2 h18 w235 vAddressBar ReadOnly, %CurDir%
Gui, 99:Add, ListBox, x2 w237 h170 vFileChoice gTest4Folder, % GetFileSubFun(CurDir,CurExt)
Gui, 99:Add, Text, x12, Type
Gui, 99:Add, DropDownList, x+10 w175 vExtDDL gChangeExt, %extList%
Gui, 99:Add, Button, x2 gUpOneLevel,^
Gui, 99:Add, Button, x+170 gCancelTheGet,Cancel
Gui, 99:Add, Button, x+-100 gGetTheFile,%Btn%
Gui, 99:Show,y25 w240 h245,%Title%
Sleep 100
WinWaitClose %Title%
Gui, 99:Destroy
Return RetValue
Test4Folder:
GuiControlGet, Selected ,, FileChoice
AttributeString := FileExist(CurDir Selected)
IfInString, AttributeString , D
{
CurDir=%CurDir%%Selected%\
GuiControl, , FileChoice, % "|" GetFileSubFun(CurDir,CurExt)
GuiControl, , AddressBar,%CurDir%
}
Else If SingleClick
{
RetValue:=CurDir . Selected
Gui, 99:Cancel
}
Return
GetTheFile:
GuiControlGet, Selected ,, FileChoice
RetValue:=CurDir . Selected
Gui, 99:Cancel
Return
UpOneLevel:
If (CurDir="\")
Return
CurDir:=SubStr(CurDir,1,InStr(SubStr(CurDir,1,-1),"\",0,0))
GuiControl, , FileChoice, % "|" GetFileSubFun(CurDir,CurExt)
GuiControl, , AddressBar,%CurDir%
Return
CancelTheGet:
Gui, 99:Cancel
Return
ChangeExt:
GuiControlGet, SelExt,, ExtDDL
If (SelExt = "All files (*.*)")
CurExt=*.*
Else
CurExt:=Ext
GuiControl,, FileChoice, % "|" GetFileSubFun(CurDir,CurExt)
Return
}
GetFileSubFun(x,Type1) { ;function that gets list of file names
Loop %x%*.*,2,0 ;loop to get folders
Var1.=A_LoopFileName "|" ;store folders in var1
Loop %x%%Type1%,0,0 ;loop to get files
Var2.=A_LoopFileName "|" ;store files in var2
Sort, Var1, D| ;Sort var1
Sort, Var2, D| ;Sort var2
Return Var1 Var2 ;return the list of folders and files
}
Edit: decided an example of usage might help
Code:
Fpath:=GetFile("\Program Files\AutoHotkeyCE\","*.ahk") ;look for script files starting in the AutoHotkeyCE folder
If (Fpath<>"Canceled") ;function returns Canceled if you hit cancel or close the gui
Run Pword.exe %Fpath% ;open the script with word
ExitApp ;Needed because the Gui in the function makes the script Persistent