Page 1 of 1
Perl file IO sucks?
Posted: Wed Mar 23, 2005 8:45 am
by pthomas
I've been trying to find different IO functions for opening files, listing directories, getting file stats and such and have come up quite sort so far. Anyone know of a good perl module or some built-in stuff that does file and directory stuff with quite a few options?
Paul
Posted: Wed Mar 23, 2005 8:50 am
by feyd
what "options" are you looking for? Perl is built alot around file handling..
Posted: Wed Mar 23, 2005 8:55 am
by pthomas
Mainly file and directory stats: size, names...
Paul
Posted: Wed Mar 23, 2005 9:34 am
by feyd
It's been a while since I've used Perl last, so I looked it up:
Code: Select all
#!/usr/bin/perl
opendir(MYDIR, '/path/to/folder') or die("e;Unable to open directory.\n"e;);
while( $file = readdir( MYDIR ) )
{
if( -d $file )
{
print( $file . "e; directory.\n"e; );
}
else
{
($device, $inode, $fileinfo, $links, $userID, $groupID, $deviceID, $size, $access, $modify, $inodeChange, $prefIO, $IO) = stat($file);
print( $file . ' ' . $size . "e;\n"e; );
}
}