Hi,
How do I know the total number of files on a disk ?
STATIC FUNCTION READFOLD()
local nFiles := 0
// Counting the main- and defined subdirectorys
local aSub := { ".\", "BMP\", "PNG\", "JPG\" }
local I, cPath, aDir
FOR EACH I in aSub
cPath := I
aDir := Directory( cPath + "*.*" )
AEval( aDir, { |a| nFiles++ } )
NEXT
MsgAlert( nFiles -= 1)
RETURN NIL
Natter wrote:Thank You, Uwe. I needed to make progressbar poll files on servers. I implemented this via diskused()
HB_FUNC( WAITRUN )
@Kernel32 -> Kernel32.DLL
#include "Ot4xb.ch"
#include "WinBase_constants.ch"
// WaitForSingleObject() returns value
* #define INFINITE 0xFFFFFFFF
#define WAIT_TIMEOUT 0x00000102
* #define WAIT_ABANDONED 0x00000080
* #define WAIT_OBJECT_0 0x00000000
* #define WAIT_OBJECT_1 ( WAIT_OBJECT_0 + 1 )
#xtranslate INVALID_HANDLE_VALUE => EMPTY
STATIC lRunAnyway := .T.
PROCEDURE MAIN
LOCAL cDir := "R:\TEMP\"
LOCAL oThread := Thread():new()
CLS
lRunAnyway := .T.
oThread:start("WatchDirectory", cDir )
WAIT "Taste drücken..."
lRunAnyway := .F.
WAIT "Taste drücken..."
lRunAnyway := .T.
oThread:start("WatchDirectory", "D:\ALASKA\SHFILE\" )
WAIT "Taste drücken..."
RETURN
FUNCTION WatchDirectory( cDir )
LOCAL pChangeHandle
LOCAL nWaitStatus
LOCAL nStart
? "WatchDirectory", cDir
// watch file name changes ( file was CREATED, RENAMED or DELETED)
pChangeHandle := @Kernel32:FindFirstChangeNotificationA( cDir, .F., FILE_NOTIFY_CHANGE_FILE_NAME )
IF INVALID_HANDLE_VALUE( pChangeHandle )
? "ERROR: FindFirstChangeNotification function failed."
RETURN @Kernel32:GetLastError()
ENDIF
// Change notification is set. Now we can wait on notification handle.
DO WHILE lRunAnyway
? "Waiting for notification..."
nStart := SECONDS()
// If the function succeeds, the return value indicates
// the event that caused the function to return.
* nWaitStatus = @Kernel32:WaitForSingleObject( pChangeHandle, INFINITE )
nWaitStatus = @Kernel32:WaitForSingleObject( pChangeHandle, 1000 )
DO CASE
CASE nWaitStatus = WAIT_OBJECT_0
// A file was CREATED, RENAMED or DELETED in the directory.
// _Refresh_ this directory and _restart_ the notification.
RefreshDir( cDir, @lRunAnyway )
IF lRunAnyway
IF EMPTY( @Kernel32:FindNextChangeNotification( pChangeHandle ) )
? "ERROR: FindNextChangeNotification function failed."
RETURN @Kernel32:GetLastError()
ENDIF
ELSE
@Kernel32:FindCloseChangeNotification( pChangeHandle )
ENDIF
EXIT
CASE nWaitStatus = WAIT_TIMEOUT
// A timeout occurred, this would happen if some value other
// than INFINITE is used in the Wait call and no changes occur.
// In a single-threaded environment you might not want an
// INFINITE wait.
? SECONDS()-nStart
* ? "No changes in the timeout period."
* EXIT
CASE nWaitStatus = WAIT_ABANDONED
? "some Error ... break loop"
EXIT
OTHERWISE
? "ERROR: Unhandled nWaitStatus."
RETURN @Kernel32:GetLastError()
ENDCASE
END WHILE
? "EXIT: Quit signal was received."
RETURN 0
/*
*/
PROCEDURE RefreshDir( cDir, lRunAnyway )
// This is where you might place code to refresh your
// directory listing, but not the subtree because it
// would not be necessary.
? "Directory "+cDir+" was changed."
IF FExists( cDir + "quit" )
lRunAnyway := .F.
ENDIF
RETURN
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 92 guests