Created
March 2, 2014 14:46
-
-
Save zwetan/9307610 to your computer and use it in GitHub Desktop.
more advanced example to list directories with redtamarin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import C.errno.*; | |
import C.stdlib.*; | |
import C.dirent.*; | |
import C.fcntl.*; | |
import C.sys.stat.*; | |
trace( "----" ); | |
/* note: | |
inspired by "Find And Open a File" example | |
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html# | |
in this path | |
$ tree -hla tmp | |
tmp | |
├── [ 0] .abc | |
├── [ 0] .def | |
├── [ 12] ghi | |
└── [ 48] jkl | |
*/ | |
var statbuf:status; | |
var d:DIR; | |
var dfd:int; | |
var ffd:int; | |
var dp:dirent; | |
var dte:Date; | |
if( (d = fdopendir( dfd = open( "./tmp", O_RDONLY ) )) == null ) | |
{ | |
trace( "Cannot open './tmp' directory" ); | |
trace( "Error# (" + int(errno) + ") " + new CError(errno) ); // Error# (9) EBADF: Bad file descriptor | |
exit(1); | |
} | |
while( (dp = readdir(d)) != null ) | |
{ | |
// ignore entries starting with dot | |
if( dp.d_name.charAt(0) == "." ) | |
{ | |
continue; | |
} | |
statbuf = new status(); | |
ffd = stat( "./tmp/" + dp.d_name, statbuf ); | |
dte = new Date(); | |
dte.setTime( statbuf.st_mtime * 1000 ); | |
trace( "entry: " + dp.d_name ); | |
trace( " - size = " + statbuf.st_size + " bytes" ); | |
trace( " - time = " + String( dte ) ); | |
} | |
closedir( d ); // this implicitly closes dfd | |
trace( "----" ); | |
trace( "bye bye program" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment