FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Number of files on a disk
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Number of files on a disk
Posted: Mon Nov 25, 2019 07:24 AM

Hi,

How do I know the total number of files on a disk ?

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Number of files on a disk
Posted: Mon Nov 25, 2019 09:21 AM
There is a freeware-tool

Foldersize 4.5.0.0

simply the best I know for the moment
it includes everything You need

https://www.techspot.com/downloads/6654 ... -size.html



Maybe You want to count only selected directorys
( could be counted from different drives )

Code (fw): Select all Collapse
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


best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Number of files on a disk
Posted: Mon Nov 25, 2019 10:06 AM

Thank You, Uwe. I needed to make progressbar poll files on servers. I implemented this via diskused()

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Number of files on a disk
Posted: Mon Nov 25, 2019 10:48 AM

I will check it.

regards
Uwe :D

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Number of files on a disk
Posted: Mon Nov 25, 2019 10:00 PM
Natter wrote:Thank You, Uwe. I needed to make progressbar poll files on servers. I implemented this via diskused()

you will make a lot traffic if nothing have change ...

there is
Code (fw): Select all Collapse
HB_FUNC( WAITRUN )
in \fwh\source\winapi\winexec.c

it will wait until "something change" in a given Directory.
i have a Xbase++ Source using ot4xb*** for this.
*** http://www.ot4xb.com
Syntax :

@Kernel32 -> Kernel32.DLL


Code (fw): Select all Collapse
#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


Code (fw): Select all Collapse
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

perhaps someone can help to convert it to harbour / FiveWin
greeting,

Jimmy

Continue the discussion