Number of files on a disk

Number of files on a disk

Postby Natter » Mon Nov 25, 2019 7:24 am

Hi,

How do I know the total number of files on a disk ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Number of files on a disk

Postby ukoenig » Mon Nov 25, 2019 9: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

Image

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

Code: Select all  Expand view


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
Last edited by ukoenig on Tue Nov 26, 2019 7:52 am, edited 2 times in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Number of files on a disk

Postby Natter » Mon Nov 25, 2019 10:06 am

Thank You, Uwe. I needed to make progressbar poll files on servers. I implemented this via diskused()
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Number of files on a disk

Postby ukoenig » Mon Nov 25, 2019 10:48 am

I will check it.

regards
Uwe :D
Last edited by ukoenig on Tue Nov 26, 2019 7:56 am, edited 2 times in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Number of files on a disk

Postby Jimmy » 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: Select all  Expand view
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  Expand view
#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  Expand view
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
User avatar
Jimmy
 
Posts: 1729
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 45 guests