How To Count Files ??

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
Richard_Schmidt
Posts: 21
Joined: Wed Jul 31, 2013 3:23 pm
Location: Germany

How To Count Files ??

Post by Richard_Schmidt »

Dear experts,

I need to count the number of files of a specific type in a directory.
For example: number of "*.pdf" or "*.mp3".

Is there a comfortable way to do this ??

I would appreciate any help or idea ..

Thanks in advance
Richard
ASESORMIX
Posts: 195
Joined: Thu Oct 25, 2012 8:08 pm
Location: Bqto, Venezuela

Re: How To Count Files ??

Post by ASESORMIX »

Directory function can help you

See: https://vivaclipper.wordpress.com/?s=directory
User avatar
serge_girard
Posts: 3173
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: How To Count Files ??

Post by serge_girard »

Richard,

Something like this maybe?

Code: Select all

aDIR  := DIRECTORY(  yourFOLDER + '\*.*', '' )
FOR A = 1 TO LEN(aDIR)
   IF '.PDF' $ UPPER(aDIR [A][1] ) 
      // COUNT
   ENDIF
   
NEXT 
There's nothing you can do that can't be done...
User avatar
Algernon
Posts: 55
Joined: Sat Mar 20, 2010 10:36 am
DBs Used: DBF
Location: Arucas, Gran Canaria, Canary Islands

Re: How To Count Files ??

Post by Algernon »

I've used it in aplication and if you only want to know the number of pdf files in a directory I think that it can help you

Code: Select all

aDIR  := DIRECTORY(  yourFOLDER + '\*.pdf', 'D' )

LEN(aDIR)

Javier Suárez

La obra humana más bella es la de ser útil al prójimo. (Sófocles)
The most beautiful work of man is to be useful to others. (Sófocles)
Pcmodula
Posts: 35
Joined: Thu Nov 22, 2012 6:00 pm

Re: How To Count Files ??

Post by Pcmodula »

Hi all, i use this to count multiple type of files

#include "hmg.ch"

FUNCTION Main ()

LOCAL i, cForm

DEFINE WINDOW Win_1 ;
TITLE 'Hello World!' ;
MAIN ;
ON INIT CountMyFiles(/*cPat,aFtype*/)

END WINDOW

cForm := "Win_1"
_DefineHotKey( cForm, 0, VK_ESCAPE, hb_MacroBlock( "_ReleaseWindow('" + cForm + "')" ) )

ACTIVATE WINDOW Win_1

RETURN NIL

*-----------------------------------------------------------------------------*
Static Function CountMyFiles( cPath, eXtSrc )
*-----------------------------------------------------------------------------*
LOCAL i, F , ntc := 0 ,aRtv:={} , cRtv :='' , vGrid
DEFAULT extSrc to {".PDF",".GIF",".TXT",".JPG",".BMP",".PNG",".EXE"}
DEFAULT cPath to cFilePath(GetExeFileName())
Asize ( aRtv, len(eXtSrc) )
Aeval (eXtSrc,{|x,y| Artv[y] :={x,0} } )

vgrid := DIRECTORY( cPath + "\*.*",)
// Put all uppercase
aeval(vGrid, {|x,y| vgrid[y,1] :=upper(x[1]) } )

// Count
FOR Each F IN vGrid
i := ascan(ExtSrc,hb_fnameExt(F[1]) )
IF i > 0
ntc := Artv[i,2] +1
Artv[i,2] := ntc
Endif
NEXT

ASort(aRtv,,, { |x, y| x[2] < y[2] })

// prepare report
FOR Each F in aRtv
if f[2] > 0
Crtv += "Found N° "+hb_ntoc(F[2]) +remleft(F[1],".") +CRLF
Else
Crtv += "Not Found "+remleft(F[1],".") +CRLF
Endif
Next

MsgInfo(Crtv,"Results:")

Return Artv

Saludos
PcModula
User avatar
Richard_Schmidt
Posts: 21
Joined: Wed Jul 31, 2013 3:23 pm
Location: Germany

Re: How To Count Files ??

Post by Richard_Schmidt »

Thank you for replies - the hints are very helpful !!
Saludos
Richard
Post Reply