count all the files in Unix directory

Hi,
how do i count all the files present in Unix directory, but not in the sudirectory from BODI.there are three files present in my Unix directory.
currently i am using following syntax:
$G_File_Count = exec( ‘ls | ls -F | grep -v / | wc -l’, ‘/bo/vikash/files/temporary’ ,2);
but it is returning null.
how ever when i checked in the Unix command prompt, “ls | ls -F | grep -v / | wc -l” is worknig fine and returning desired result. but i am calling from BODI, it is returning null.
can any one help me out???


vikashcvrce303 :india: (BOB member since 2012-02-13)

Try this code for your file count variable, it should work

exec(’/bin/sh’, '-c “ls /bo/vikash/files/temporary |grep -v / | wc -l” ’ ,2);

Note: verify the /bin/sh command path in your jobserver. If your directory consists of child directories the count includes them also.

Good Luck


kirankk4u (BOB member since 2009-10-16)

Hi Kiran,

Can you help me with modification of this code to get the files starting with ATW*.txt? and if possible exclude child directory??

Appreciate any help!!
Thanks[/code]


BODSDW (BOB member since 2011-01-19)

python

fp = r'C:\Documents and Settings\jlb943\Desktop\testMe'
from os import listdir,path
lstFiles = [n for n in listdir(fp) if path.isfile(fp + '\\' + n) and n.upper().startswith('ATW') and n.upper().endswith('.TXT')]
print len(lstFiles)

jlynn73 :us: (BOB member since 2009-10-27)

do you mean it’s a Python code? how does it help me in UNIX?? :o


BODSDW (BOB member since 2011-01-19)

python is for the most part platform independent. I’ll write it in windows and run it on AIX with no changes.

I dont know unix :oops: but python is a no-brainer. :cheers:


jlynn73 :us: (BOB member since 2009-10-27)