Jump to page: 1 2
Thread overview
Why doesn't listdir() work?
Jul 12, 2004
kinghajj
Jul 12, 2004
Ben Hinkle
Jul 12, 2004
Vathix
Jul 13, 2004
kinghajj
Jul 13, 2004
Vathix
Jul 12, 2004
kinghajj
Jul 12, 2004
Ben Hinkle
Jul 13, 2004
Matthew
Jul 13, 2004
Matthew
Jul 13, 2004
kinghajj
Jul 13, 2004
Matthew
Jul 13, 2004
Juanjo Álvarez
Jul 13, 2004
Matthew Wilson
July 12, 2004
My code:

import std.file;

int main(char[][] args)
{
if(args.length != 2)
{
return 0;
}

if(exists(args[1]) && isdir(args[1]))
{
char[][] contents = listdir(args[1]);
printf("Directory listing for %.*s:\n\n", args[1]);
for(int i = 0;i < contents.length;i++)
{
printf("%.*s", contents);
}
}
return 0;
}

Why won't listdir() work?
I'm using DMD 0.95 on Linux (Fedora Core 2).


July 12, 2004
kinghajj wrote:

> My code:
> 
> import std.file;
> 
> int main(char[][] args)
> {
> if(args.length != 2)
> {
> return 0;
> }
> 
> if(exists(args[1]) && isdir(args[1]))
> {
> char[][] contents = listdir(args[1]);
> printf("Directory listing for %.*s:\n\n", args[1]);
> for(int i = 0;i < contents.length;i++)
> {
> printf("%.*s", contents);
> }
> }
> return 0;
> }
> 
> Why won't listdir() work?
> I'm using DMD 0.95 on Linux (Fedora Core 2).

This might have something to do with it. From std/file.d:

char[][] listdir(char[] pathname)
{
    assert(0);          // BUG: not implemented
    return null;
}

July 12, 2004
"Ben Hinkle" <bhinkle4@juno.com> wrote in message news:ccv4m4$cm5$1@digitaldaemon.com...
> kinghajj wrote:
>
> > My code:
> >
> > import std.file;
> >
> > int main(char[][] args)
> > {
> > if(args.length != 2)
> > {
> > return 0;
> > }
> >
> > if(exists(args[1]) && isdir(args[1]))
> > {
> > char[][] contents = listdir(args[1]);
> > printf("Directory listing for %.*s:\n\n", args[1]);
> > for(int i = 0;i < contents.length;i++)
> > {
> > printf("%.*s", contents);
> > }
> > }
> > return 0;
> > }
> >
> > Why won't listdir() work?
> > I'm using DMD 0.95 on Linux (Fedora Core 2).
>
> This might have something to do with it. From std/file.d:
>
> char[][] listdir(char[] pathname)
> {
>     assert(0);          // BUG: not implemented
>     return null;
> }
>

I implemented it quite awhile ago and it was never used: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/796


July 12, 2004
In article <ccv4m4$cm5$1@digitaldaemon.com>, Ben Hinkle says...

>This might have something to do with it. From std/file.d:
>
>char[][] listdir(char[] pathname)
>{
>    assert(0);          // BUG: not implemented
>    return null;
>}
>

No, becuase on mine the function is this:

char[][] listdir(char[] pathname)
{
char[][] result;
char[] c;
HANDLE h;

c = std.path.join(pathname, "*.*");
if (useWfuncs)
{
WIN32_FIND_DATAW fileinfo;

h = FindFirstFileW(std.utf.toUTF16z(c), &fileinfo);
if (h != INVALID_HANDLE_VALUE)
{
do
{   int i;
int clength;

// Skip "." and ".."
if (std.string.wcscmp(fileinfo.cFileName, ".") == 0 ||
std.string.wcscmp(fileinfo.cFileName, "..") == 0)
continue;

i = result.length;
result.length = i + 1;
clength = std.string.wcslen(fileinfo.cFileName);
result[i] = std.utf.toUTF8(fileinfo.cFileName[0 .. clength]);
} while (FindNextFileW(h,&fileinfo) != FALSE);
FindClose(h);
}
}
else
{
WIN32_FIND_DATA fileinfo;

h = FindFirstFileA(toMBSz(c), &fileinfo);
if (h != INVALID_HANDLE_VALUE)
{
do
{   int i;
int clength;
wchar[] wbuf;
int n;

// Skip "." and ".."
if (std.string.strcmp(fileinfo.cFileName, ".") == 0 ||
std.string.strcmp(fileinfo.cFileName, "..") == 0)
continue;

i = result.length;
result.length = i + 1;
clength = std.string.strlen(fileinfo.cFileName);

//result[i] = fileinfo.cFileName[0 .. clength].dup;

// Convert cFileName[] to unicode
wbuf.length = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,null,0);
n =
MultiByteToWideChar(0,0,fileinfo.cFileName,clength,cast(wchar*)wbuf,wbuf.length);
assert(n == wbuf.length);
result[i] = std.utf.toUTF8(wbuf);

} while (FindNextFileA(h,&fileinfo) != FALSE);
FindClose(h);
}
}
return result;
}

Maybe it's Windows-only?


July 12, 2004
> Maybe it's Windows-only?

yup - the OP said they were on Linux. The Windows version is fine.
July 13, 2004
Why not use std.recls?

"kinghajj" <kinghajj_member@pathlink.com> wrote in message news:ccv3l5$bk3$1@digitaldaemon.com...
> My code:
>
> import std.file;
>
> int main(char[][] args)
> {
> if(args.length != 2)
> {
> return 0;
> }
>
> if(exists(args[1]) && isdir(args[1]))
> {
> char[][] contents = listdir(args[1]);
> printf("Directory listing for %.*s:\n\n", args[1]);
> for(int i = 0;i < contents.length;i++)
> {
> printf("%.*s", contents);
> }
> }
> return 0;
> }
>
> Why won't listdir() work?
> I'm using DMD 0.95 on Linux (Fedora Core 2).
>
>


July 13, 2004
"Matthew" <admin@stlsoft.dot.dot.dot.dot.org> escribió en el mensaje
news:ccvb87$mht$1@digitaldaemon.com...
| Why not use std.recls?
|

I think listdir should work anyway, don't you?

-----------------------
Carlos Santander Bernal


July 13, 2004
"Carlos Santander B." <carlos8294@msn.com> wrote in message news:ccvc8d$o78$1@digitaldaemon.com...
> "Matthew" <admin@stlsoft.dot.dot.dot.dot.org> escribió en el mensaje
> news:ccvb87$mht$1@digitaldaemon.com...
> | Why not use std.recls?
> |
>
> I think listdir should work anyway, don't you?

Of course. I was just being practical, to get him working right now. :)


July 13, 2004
In article <ccvb87$mht$1@digitaldaemon.com>, Matthew says...
>
>Why not use std.recls?
>

I thought that that wasn't in the library yet. I'll check it out :)


July 13, 2004
In article <ccv5go$e9i$1@digitaldaemon.com>, Vathix says...

>I implemented it quite awhile ago and it was never used: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/796
>
>

I can't decode the base64... the quick base64 encoder/decoder (written in D :)
that I made says that the string is invalid (I removed all of the newlines).

Can you re-post the code without using the base64 encoding?


« First   ‹ Prev
1 2