Alternative File Search v1.2.0.0
################################################################
The path field allows either single path (C:\My Path) or a colon-separated list of paths (D:\Downloads|E:\Pictures\This summer).
The name field accepts exact name ('thisname' will search for files named exactly 'thisname') - currently doesn't work!!! - all names (a single asterisk *) or any name beginning with (thisn* will search for any files whose names begin with 'thisn').
The extensions field allows either single extension, colon-delimited list of extensions (similar to 'path' above) or all extensions (a single asterisk). Partial extensions (such as ex*) are not supported.
Do not append backslashes or the search function will fail - there is no built-in check for badly formatted input (yet).
Do not append or prepend a colon to any of the fields.
################################################################
The function:
unsigned int FileFindFilter(
LPTSTR dirs,
LPTSTR ext,
LPTSTR name,
BOOL rec,
FFFCBK cbk
);
dirs [in] String containing path or list of colon-separated paths to search in. No wildcard accepted.
ext [in] String containing single asterisk wildcard, file extension or list of colon-separated extensions to search for.
name [in] String containing any combination of allowed characters as a file name, optionally ending in single asterisk wildcard.
rec [in] BOOL that enables or disables recursion into foders.
cbk [in] User-defined callback function's address.
Return value:
Currently, the function returns the total count of files found. Later versions might return a double containing both folder count in higher DWORD and files count in lower DWORD.
Details:
Function must be called using CDecl convention. The callback must be created with CDecl too. This may or may not change in a later version.
Internally, upon each call the function will call the callback function with path=FALSE and name=FALSE, which allows for initialization of static parameters inside the callback function.
Upon exit, the function will call the callback again, this time with path=FALSE and name=HINSTANCE g_hInstance, which allows for saving static data and/or cleanup inside callback.
Although the function library was built using Unicode-aware API, it still isn't optimized for a Unicode environment. Therefore I have no idea how it will perform in such situation; any feedback on this would be welcome.
################################################################
The callback:
VOID CALLBACK UserCallback(
LPVOID path,
LPVOID name,
LPTSTR ext,
LPTSTR short,
LPTSTR attr
);
What you do in the callback is entirely your business. The main function provides the information, you use the callback to modify/store/display it in whatever format you see fit.
The attributes member currently receives a string of attributes in a predefined format; a DWORD version may be available at a later time, if requested.
The name field contains the file extension attached.
The path field only contains the path, not the file name.
The short (8.3) name may not be present in all file names, therefore it may come up blank for certain files.
################################################################
Example:
AW := A_IsUnicode ? "W" : "A"
Ptr := A_IsUnicode ? "Ptr" : "UInt"
AStr := A_IsUnicode ? "AStr" : "Str"
mycbk := RegisterCallback("userCbk", "CDecl F", 5, "")
filepath := "C:"
filename := "*"
filext := "*"
recSw := 0x1 ; FFF_RECURSE
hFFF := DllCall("LoadLibrary" AW, "Str","fff.dll")
count := DllCall("fff\FileFindFilter", "Str", filepath, "Str", filext, "Str", filename, "UInt", recSw, (A_IsUnicode ? Ptr : "UInt"), mycbk, "CDecl UInt")
DllCall("FreeLibrary", (A_IsUnicode ? Ptr : "UInt"), hFFF)
FileAppend, `nFound %count% files`n, Search results.txt
Run, Search results.txt,, UserErrorLevel
return
userCbk(p, n, e, s, a)
{
Static
Global AW, Ptr, AStr
Critical
if !hK
{
hK := DllCall("GetModuleHandle" AW, "Str", "kernel32")
hPMD := DllCall("GetProcAddress", Ptr, hK, AStr, "MulDiv")
}
if !p
return
fPath := DllCall(hPMD, Ptr, p, "Int", 1, "Int", 1, "Str")
fName := DllCall(hPMD, Ptr, n, "Int", 1, "Int", 1, "Str")
sName := DllCall(hPMD, Ptr, s, "Int", 1, "Int", 1, "Str")
fExt := DllCall(hPMD, Ptr, e, "Int", 1, "Int", 1, "Str")
fAttr := DllCall(hPMD, Ptr, a, "Int", 1, "Int", 1, "Str")
FileAppend, %fPath%\%fName% (%fExt%)`t%sName%`t%fAttr%`n, Search results.txt
}
################################################################
This is free software. Use at your own risk.
Alternative File Search © Drugwash 2012