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
How To Count Files ??
Moderator: Rathinagiri
- Richard_Schmidt
- Posts: 21
- Joined: Wed Jul 31, 2013 3:23 pm
- Location: Germany
- serge_girard
- Posts: 3176
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: How To Count Files ??
Richard,
Something like this maybe?
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...
- 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 ??
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)
Re: How To Count Files ??
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
#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
- Richard_Schmidt
- Posts: 21
- Joined: Wed Jul 31, 2013 3:23 pm
- Location: Germany
Re: How To Count Files ??
Thank you for replies - the hints are very helpful !!
Saludos
Richard
Saludos
Richard