[SOLVED]Help with file listing

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

[SOLVED]Help with file listing

Post by ne0h »

Excuse me,
i've a function to list all file in a dir:

Code: Select all

n = scandir(dir, &namelist, 0, alphasort);
b=n;
while(b--){
                      if(a!=n){     
                      a++;
		              printf("%s\n", namelist[a]->d_name);
                      }
                      }
but this funct show all the file in the directory!
I will show only the name of the file, not the "." and ".."!

Code: Select all


if ((strcmp(namelist[a]->d_name,".") == 0)
....

but this function don't work correctly! How to resolve?

( Excuse me for my english, i'm italian )
Last edited by ne0h on Fri Mar 28, 2008 6:22 am, edited 1 time in total.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

huh this forum is for PSP development not for C teaching, your question is an evidence about the fact you don't master C and so I may question your choice about messing up with psardump as well.

that would be the last answer I would give you :

strcmp("..", ".") is strictly equivalent to say : does the ".." sequence equal to the "." sequence, which is obviously always false. What you seem to want to do is : is the first character a "." ? which is not enough indeed.

The real thing to do is :

Code: Select all

if ((filename[0] != '.') ||
   ((filename[1] != '\0') &&  ((filename[1] != '.') || (filename[2] != '\0'))))
    ...
with this code, you're only excluding "." and "..", if a file is named "..hello", it wouldn't be excluded.
Post Reply