No, A_LoopFileLongPath is only valid inside a loop.
I noticed "asynchronous" mode is actually achieved via an "overlapped operation." Since I have written code for such before, I thought I'd apply it to FolderSpy.
The modified ReadDirectoryChanges():
Code:
ReadDirectoryChanges() { ; http://msdn2.microsoft.com/en-us/library/aa365465.aspx
Global hDir,PointerFNI, Sizeof_FNI, WatchSubdirs
; Create an event object and OVERLAPPED structure.
hEvent := DllCall("CreateEvent", UInt, 0, Int, true, Int, false, UInt, 0)
VarSetCapacity(Overlapped, 20, 0), NumPut(hEvent, Overlapped, 16)
; Call ReadDirectoryChangesW in overlapped/asynchronous mode.
if !DllCall( "ReadDirectoryChangesW"
, UInt , hDir
, UInt , PointerFNI
, UInt , SizeOf_FNI
, UInt , WatchSubDirs
, UInt , ( FILE_NOTIFY_CHANGE_FILE_NAME := 0x1 )
| ( FILE_NOTIFY_CHANGE_DIR_NAME := 0x2 )
| ( FILE_NOTIFY_CHANGE_ATTRIBUTES := 0x4 )
| ( FILE_NOTIFY_CHANGE_SIZE := 0x8 )
| ( FILE_NOTIFY_CHANGE_LAST_WRITE := 0x10 )
| ( FILE_NOTIFY_CHANGE_LAST_ACCESS := 0x20 )
| ( FILE_NOTIFY_CHANGE_CREATION := 0x40 )
| ( FILE_NOTIFY_CHANGE_SECURITY := 0x100 )
, UIntP, nReadLen
, UInt , &Overlapped
, UInt , 0 )
return false ; error?
Loop {
; Wait for the event to be signaled, or any window message received.
r := DllCall("MsgWaitForMultipleObjectsEx", UInt, 1, UIntP, hEvent
, UInt, -1, UInt, 0x4FF, UInt, 0x6)
if (r = 0) || (r = -1) ; WAIT_OBJECT_0 or WAIT_FAILED
break
Sleep, 1 ; Allow AutoHotkey to process/dispatch messages.
}
DllCall( "CloseHandle", UInt,hEvent )
return DllCall( "GetOverlappedResult", UInt, hDir
, UInt, &Overlapped, UIntP, nReadLen, Int, true )
}
...and simplified loop in WatchFolder:
Code:
Loop {
ReadDirectoryChanges()
GoSub, Decode_FILE_NOTIFY_INFORMATION
Sleep 100
If !Watch
Break
}
Btw, it seems FolderSpy does not allow the user (me) to select the root of a drive. (File/folder loops don't seem to consider it a folder...)