How do I print the file list of a directory into another file in Perl? -


i tried

system("ls > file");  

in perl script when open file, empty file while directory has list of file.

my $dirpath = "./"; $filepath = "./file";  opendir(dir, $dirpath) or die("cannot open directory: $!"); open(out, ">$filepath");  foreach( sort readdir(dir) ){     next if $_ =~ /^\.{1,2}$/; # ignore "." , ".."     print(out "$_\n"); }  close(out); closedir(dir); 

note if have output file in directory listing, listed since have open before reading directory.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -