4700 ms - List
845 ms - Map
List
Code: Select all
EnableExplicit
Structure Files
Size.q
List Path.s()
EndStructure
NewList FilesPS.Files()
Procedure FileSearch(List FilesPS.Files(), sPath.s, Mask$ = "*", depth=130, level = 0)
Protected sName.s, c = 0, LenSPath, tmp$, Size.q
Protected Dim aExaDir(depth)
Protected Dim aSePath.s(depth)
Protected fNotFind
If Right(sPath, 1) <> #PS$
sPath + #PS$
EndIf
LenSPath = Len(sPath)
aSePath(c) = sPath
aExaDir(c) = ExamineDirectory(#PB_Any, sPath, Mask$)
If Not aExaDir(c)
ProcedureReturn
EndIf
Repeat
While NextDirectoryEntry(aExaDir(c))
sName=DirectoryEntryName(aExaDir(c))
If sName = "." Or sName = ".."
Continue
EndIf
If DirectoryEntryType(aExaDir(c)) = #PB_DirectoryEntry_Directory
If c >= depth
Continue
EndIf
sPath = aSePath(c)
c + 1
aSePath(c) = sPath + sName + #PS$
aExaDir(c) = ExamineDirectory(#PB_Any, aSePath(c), Mask$)
If Not aExaDir(c)
c - 1
EndIf
Else
tmp$ = aSePath(c) + sName
Size = FileSize(tmp$)
fNotFind = 1
ForEach FilesPS()
If FilesPS()\Size = Size
If AddElement(FilesPS()\Path())
FilesPS()\Path() = tmp$
EndIf
fNotFind = 0
Break
EndIf
Next
If fNotFind
If AddElement(FilesPS())
FilesPS()\Size = Size
If AddElement(FilesPS()\Path())
FilesPS()\Path() = tmp$
EndIf
EndIf
EndIf
EndIf
Wend
FinishDirectory(aExaDir(c))
c - 1
Until c < 0
EndProcedure
Define StartTime.q, time$
StartTime = ElapsedMilliseconds()
FileSearch(FilesPS(), "/home/user")
time$ = Str(ElapsedMilliseconds() - StartTime)
MessageRequester("", time$) ; output without a debugger
Debug time$ + #CRLF$
Debug "Map size: " + Str(ListSize(FilesPS())) + #CRLF$
ForEach FilesPS()
Debug #CRLF$ + Str(FilesPS()\Size)
ForEach FilesPS()\Path()
Debug FilesPS()\Path()
Next
Next
Code: Select all
EnableExplicit
Structure Files
List Path.s()
EndStructure
NewMap FilesPS.Files()
Procedure FileSearch(Map FilesPS.Files(), sPath.s, Mask$ = "*", depth=130, level = 0)
Protected sName.s, c = 0, LenSPath, tmp$, Size$
Protected Dim aExaDir(depth)
Protected Dim aSePath.s(depth)
If Right(sPath, 1) <> #PS$
sPath + #PS$
EndIf
LenSPath = Len(sPath)
aSePath(c) = sPath
aExaDir(c) = ExamineDirectory(#PB_Any, sPath, Mask$)
If Not aExaDir(c)
ProcedureReturn
EndIf
Repeat
While NextDirectoryEntry(aExaDir(c))
sName=DirectoryEntryName(aExaDir(c))
If sName = "." Or sName = ".."
Continue
EndIf
If DirectoryEntryType(aExaDir(c)) = #PB_DirectoryEntry_Directory
If c >= depth
Continue
EndIf
sPath = aSePath(c)
c + 1
aSePath(c) = sPath + sName + #PS$
aExaDir(c) = ExamineDirectory(#PB_Any, aSePath(c), Mask$)
If Not aExaDir(c)
c - 1
EndIf
Else
tmp$ = aSePath(c) + sName
Size$ = Str(FileSize(tmp$))
If FindMapElement(FilesPS(), Size$)
If AddElement(FilesPS()\Path())
FilesPS()\Path() = tmp$
EndIf
Else ; иначе если не существует
If AddMapElement(FilesPS(), Size$, #PB_Map_NoElementCheck)
If AddElement(FilesPS()\Path())
FilesPS()\Path() = tmp$
EndIf
EndIf
EndIf
EndIf
Wend
FinishDirectory(aExaDir(c))
c - 1
Until c < 0
EndProcedure
Define StartTime.q, time$
StartTime = ElapsedMilliseconds()
FileSearch(FilesPS(), "/home/user")
time$ = Str(ElapsedMilliseconds() - StartTime)
MessageRequester("", time$) ; output without a debugger
Debug time$ + #CRLF$
Debug "Map size: " + Str(MapSize(FilesPS())) + #CRLF$
ForEach FilesPS()
Debug #CRLF$ + MapKey(FilesPS())
ForEach FilesPS()\Path()
Debug FilesPS()\Path()
Next
Next