Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Next = 500
IDC_Previous
End Enum
Global hDlg As Dword, CFN As String
Function PBMain() As Long
CFN = Exe.Full$
Dialog Default Font "Tahoma", 10, 0
Dialog New Pixels, 0, CFN,300,300,500,100, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Previous,"Previous", 50,10,100,20
Control Add Button, hDlg, %IDC_Next,"Next", 50,50,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Next
CFN = CycleThroughFilesInFolder(+1, CFN, ".exe.bas.log.dll")
Dialog Set Text hDlg, CFN
Case %IDC_Previous
CFN = CycleThroughFilesInFolder(-1, CFN, ".exe.bas.log.dll")
Dialog Set Text hDlg, CFN
End Select
End Select
End Function
Function CycleThroughFilesInFolder(Direction As Long, CurrentFile$, ExtMask$) As String
Local temp$, FilePath$, FileList$, i,iPos As Long
'put all matching files in an array, LCase$ everything
FilePath$ = LCase$(PathName$(Path,CurrentFile$))
temp$ = LCase$(Dir$(FilePath$ + "*.*"))
Do While Len(temp$)
If InStr(ExtMask$,LCase$(PathName$(Extn,temp$))) Then FileList$ += FilePath$ + LCase$(temp$) + $CrLf
temp$ = Dir$(Next)
Loop
FileList$ = Trim$(FileList$,$CrLf)
ReDim FileArray(ParseCount(FileList$,$CrLf)-1) As String
Parse FileList, FileArray(), $CrLf
Array Sort FileArray()
If UBound(FileArray) = 0 Then Function = CurrentFile$ : Exit Function 'there is only one file, so returns that fle
'find current file in array
temp$ = FilePath$ + LCase$(PathName$(Namex,CurrentFile$))
For i = 0 To UBound(FileArray)
If FileArray(i) = temp$ Then iPos = i : Exit For
Next i
'get file in specified direction
If Direction = +1 Then 'Next 'get next item. if is last, go to first. if is only, return the same
If iPos < UBound(FileArray) Then Function = FileArray(iPos+1) : Exit Function
If iPos = UBound(FileArray) Then Function = FileArray(0) : Exit Function
ElseIf Direction = -1 Then 'Previous 'get previous item. if is first, go to last. if is only, return the same
If iPos > 0 Then Function = FileArray(iPos-1) : Exit Function
If iPos = 0 Then Function = FileArray(UBound(FileArray)) : Exit Function
End If
End Function
http://www.garybeene.com/sw/gbsnippets.htm