i'm beginner python , i'm trying list contents of directory defined variable no avail.
this code:
#!/usr/bin/python import os location = "/home/itaig/testdir" command = os.system('ls -l')," location" my aim count number of files in location , print number.
how can achieved?
edit #1:
in bash i'd ls -l $location | wc -l , equivalent in python?
in case, i've looked @ links comments wasn't able work... can please show me example?
thanks
you can use os.listdir. platform independent os module handle low level work
print len(os.listdir(location))
Comments
Post a Comment