Created
May 22, 2015 07:27
-
-
Save arakov/6be668b516cbb367fd42 to your computer and use it in GitHub Desktop.
ELENA: File Searching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define system. | |
#define system'text. | |
#define extensions'text. | |
#class FileEnumerator | |
{ | |
#field(type:bytearray)theStruct. | |
#field theHandle. | |
#field theSearchPath. | |
#field theOpen. | |
#constructor new &path:aPath | |
[ | |
theStruct := ByteArray new &length:592. | |
theSearchPath := aPath wide. | |
theOpen := false. | |
] | |
#method next | |
[ | |
($nil == theHandle) | |
? [ | |
#var(type:handle)aHandle := system'external'KERNEL32 FindFirstFileW | |
&wide:(theSearchPath wide) | |
&bytearray:theStruct. | |
(aHandle == -1) | |
! [ theOpen := true. ]. | |
theHandle := Handle new &handle:aHandle. | |
] | |
! [ | |
#var(type:int)aRetVal := system'external'KERNEL32 FindNextFileW | |
&handle:(theHandle handle) | |
&bytearray:theStruct. | |
(aRetVal != 0) | |
! [ theOpen := false. ]. | |
]. | |
^ theOpen. | |
] | |
#method get | |
[ | |
theOpen | |
? [ | |
#var(type:int)aFileLength := 0. | |
#var(type:bytearray,size:520)aNameBuffer. | |
theStruct read &index:44 &length:520 &bytearray:aNameBuffer. | |
// define length | |
aFileLength := system'external'KERNEL32 lstrlenW &bytearray:aNameBuffer. | |
^ UTF16Encoder::encoderOp toWide &bytearray:aNameBuffer &length:(aFileLength * 2). | |
] | |
! [ ^ $nil. ]. | |
] | |
#method free | |
[ | |
system'external'KERNEL32 FindClose &handle:(theHandle handle). | |
] | |
} | |
#symbol Program = | |
[ | |
#var en := FileEnumerator new &path:"c:\*.*". | |
#loop (en next)? | |
[ | |
console writeLine:(en get). | |
]. | |
en free. | |
]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment