Access all classes in a directory, put into an array, and print t hem out

Oleg Broytmann phd at phd.fep.ru
Tue Jul 3 10:15:38 EDT 2001


On Tue, 3 Jul 2001, Kemp Randy-W18971 wrote:
> Can anyone share a short code example of how to access all the programs in a
> Unix directory, put them into an array, and print them out in Python?  Here
> is the code I have to do it in Perl (please forgive the harsh language).
>
> #!/usr/bin/perl -w
> #use Net::FTP;
> opendir (TEMP, '/usr2/ecadtesting/javaprograms')
>   or die "Can't open current directory.";
> @files=join(',',grep(!/^\.\.?$/, readdir TEMP));

   This program does completely different thing from your description - it
collects all files, not only programs.

   Well, in Python the program to collect all files (not programs) is:

#!/usr/bin/python -O
import string, os
print string.join(os.listdir('/usr2/ecadtesting/javaprograms'), ',')

Oleg.
----
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list