Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_TreeView = 500
%IDC_ListView = 501
%IDC_ButtonSelect = 502
%IDC_TextBox = 503
%IDC_ButtonAnalyze = 504
Global hDlg As Dword, Folders(), Files(), CurrentFolder As String
Global FolderCount As Long, FileCount As Long
Function PBMain() As Long
Dim Folders(10000), Files(100000)
Dialog New Pixels, 0, "Folder Analysis",300,100,700,450,%WS_OverlappedWindow, 0 To hDlg
Control Add Button, hDlg, %IDC_ButtonSelect, "Select Folder", 10,10,100,20
Control Add TextBox, hDlg, %IDC_TextBox, "c:\data\rod", 120,10,400,20
Control Add Button, hDlg, %IDC_ButtonAnalyze, "Analyze Folder", 540,10,100,20
CreateListView
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IdOk : AnalyzeFolder
Case %IDC_ButtonSelect : SelectFolder
Case %IDC_ButtonAnalyze : AnalyzeFolder
End Select
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_ListView, w-20,h-50
End Select
End Function
Sub CreateListView
Control Add ListView, hDlg, %IDC_ListView, "", 10,40,370,400
'columns hdlg, id&, col, "test", width, format
ListView Insert Column hDlg, %IDC_ListView, 1, "Folder", 250, 0
ListView Insert Column hDlg, %IDC_ListView, 2, "File", 150, 0
ListView Insert Column hDlg, %IDC_ListView, 3, "Size", 125, 0
ListView Insert Column hDlg, %IDC_ListView, 4, "Date", 125, 0
End Sub
Sub ListFiles
'uses the Folders() array to populates Files() array
Local i As Long, file$, FileData As DirData, temp$, lft As FileTime, st As SystemTime
For i = 0 To UBound(Folders)
file$ = Dir$(Folders(i) + "\*.*", To FileData)
While Len(file$)
Files(FileCount) = Folders(i) + "\" + file$
'put stuff about file into ListView --------------------
ListView Insert Item hDlg, %IDC_ListView, FileCount+1, 1, PathName$(Path, Files(FileCount))
ListView Set Text hDlg, %IDC_ListView, FileCount+1,2, PathName$(Namex, Files(FileCount))
ListView Set Text hDlg, %IDC_ListView, FileCount+1,3, Str$(FileData.FileSizeHigh * &H100000000 + FileData.FileSizeLow)
FileTimeToLocalFileTime(ByVal VarPtr(FileData.LastWriteTime), lft)
FileTimeToSystemTime(lft, st)
temp$ = Format$(st.wYear)+"/"+Format$(st.wMonth, "00")+"/"+Format$(st.wDay,"00") + " " + Format$(st.wHour, "0#")+":"+Format$(st.wMinute, "0#")
ListView Set Text hDlg, %IDC_ListView, FileCount+1,4, temp$
'-------------------------------------------------------
Incr FileCount
file$ = Dir$
Wend
Next i
ReDim Preserve Files(FileCount)
End Sub
Sub ListSubFolders
Local iPOS As Long, temp$
Control Get Text hDlg, %IDC_TextBox To CurrentFolder
If IsFalse(IsFolder(CurrentFolder)) Then
MsgBox "Bad folder name!", %MB_Ok + %MB_IconExclamation, "Analyze Folder"
Exit Sub
End If
Folders(FolderCount) = CurrentFolder
While Len(Folders(iPOS))
temp$ = Dir$(Build$(Folders(iPOS),"\*.*"), Only %SubDir) 'subfolders only
While Len(temp$)
Incr FolderCount
Folders(FolderCount) = Build$(Folders(iPos),"\",temp$)
temp$ = Dir$ (Next)
Wend
Incr iPOS
Wend
ReDim Preserve Folders(FolderCount)
End Sub
Sub AnalyzeFolder
Control Get Text hDlg, %IDC_TextBox To CurrentFolder
If IsFolder(CurrentFolder) Then
ListSubFolders
ListFiles
Else
MsgBox "Bad folder name!", %MB_Ok + %MB_IconExclamation, "Analyze Folder"
End If
End Sub
Sub SelectFolder
Local title$, start$, flags&, folder$
title$ = "Select Folder"
start$ = CurrentFolder
flags& = %BIF_ReturnOnlyFSDirs Or %BIF_DontGoBelowDomain Or %BIF_NoNewFolderButton
Display Browse hDlg, 100, 100, title$, start$, flags& To folder$ 'folder$ is set to "" if Cancel/Escape is pressed
If Len(folder$) Then
CurrentFolder = folder$
Control Set Text hDlg, %IDC_TextBox, CurrentFolder
End If
End Sub
'gbs_00983
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm