Snappy! - 2005-11-28 2:55 PM
I see that you are doing a recursive call right now, but your function dirlist seem a bit more complex than it should or need be.
Maybe you can dump the output for us?
See my comments inside
dirlist(string path)
{
string out,rpath,fn;
int cnt=0,fa;
rpath=path+"*";
// enumerate files in rpath
out=fileenum(1,rpath);
while(out)
{
// if current file is a directory, recurse
fn=path+out+"\\"; // <--- this is a wrong assumption
fa=GetFileAttr(fn);
if((fa&0x00000010)&&fa!=-1)
{
putsl(path+out);
cnt=cnt+dirlist(fn);
cnt++; // <--- might as well put this outside
}
// begin suggested mod
else if (!(GetFileAttr(fn)&0x00000010)) // If file is a normal file bla bla bla
{
putsl(path+out);
}
cnt++; // <--- might as well put this outside
// end suggested mod
out=fileenum(0,rpath); // <--- get next file in enum list
}
// Why have another loop to list out files when it can be done above?
out=fileenum(1,rpath);
while(out)
{
fn=path+out;
if(!(GetFileAttr(fn)&0x00000010))
{
putsl(path+out);
cnt++;
}
out=fileenum(0,rpath);
}
return cnt;
}
main()
{
showconsole();
putsl(dirlist("\\Windows\\Programme\\" ));
}
Not too sure about specific syntax for PocketC, but here's how I would write the main loop in dirlist:
// enumerate files in rpath
out=fileenum
(1,rpath
);
while
(out
)
{
// if current file is a directory, recurse
fn=path+out;
fa=GetFileAttr
(fn
);
if
(
(fa&0x00000010
)&&fa!=-1
)
{
putsl
(path+out+"\\"
;
cnt=cnt+dirlist
(fn
);
}
else if
(!
(GetFileAttr
(fn
)&0x00000010
)
) // If file is a normal file bla bla bla
{
putsl
(path+out
);
}
cnt++; // <--- might as well put this outside
out=fileenum
(0,rpath
); // <--- get next file in enum list
}
I am assuming you got the string syntax correct so I am not doing checks on that. Also, I am assuming that the Fileattribute check flags are working fine to start with.
Hope this helps.