forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED]Help with file listing

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Sat Mar 22, 2008 11:07 pm    Post subject: [SOLVED]Help with file listing Reply with quote

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

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:


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
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Sat Mar 22, 2008 11:34 pm    Post subject: Reply with quote

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:
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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group