Page 1 of 1

Number of files on a disk

Posted: Mon Nov 25, 2019 7:24 am
by Natter
Hi,

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

Re: Number of files on a disk

Posted: Mon Nov 25, 2019 9:21 am
by ukoenig
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

Image

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

Code: Select all


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 :D

Re: Number of files on a disk

Posted: Mon Nov 25, 2019 10:06 am
by Natter
Thank You, Uwe. I needed to make progressbar poll files on servers. I implemented this via diskused()

Re: Number of files on a disk

Posted: Mon Nov 25, 2019 10:48 am
by ukoenig
I will check it.

regards
Uwe :D

Re: Number of files on a disk

Posted: Mon Nov 25, 2019 10:00 pm
by Jimmy
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: Select all

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: Select all

#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: Select all

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