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 

List files problem

 
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: Wed Mar 19, 2008 3:12 am    Post subject: List files problem Reply with quote

Excuse me, but i use this function to get the name of the files in a directory, but I don't wan't to read "." and "..", i've try this many times but
now for this function i haven't a functionally solutions!
Can anyone help me?
And if i want to print to screen only file .xxx?


Code:

int scandir(const char *dir, struct dirent ***namelist,
            int (*select)(const struct dirent *),
            int (*compar)(const struct dirent **, const struct dirent **))
{
  DIR *d;
  struct dirent *entry;
  register int i=0;
  size_t entrysize;

  if ((d=opendir(dir)) == NULL)
     return(-1);

  *namelist=NULL;
  while ((entry=readdir(d)) != NULL)
  {
    if (select == NULL || (select != NULL && (*select)(entry)))
    {
      *namelist=(struct dirent **)realloc((void *)(*namelist),
                 (size_t)((i+1)*sizeof(struct dirent *)));
   if (*namelist == NULL) return(-1);
   entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1;
   (*namelist)[i]=(struct dirent *)malloc(entrysize);
   if ((*namelist)[i] == NULL) return(-1);
   memcpy((*namelist)[i], entry, entrysize);
   i++;
    }
  }
  if (closedir(d)) return(-1);
  if (i == 0) return(-1);
  if (compar != NULL)
    qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar);
   
  return(i);
}

Tanks in advance!


Last edited by ne0h on Thu Mar 20, 2008 3:57 am; edited 2 times in total
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Wed Mar 19, 2008 3:57 am    Post subject: Reply with quote

I've look here: http://www.cs.cf.ac.uk/Dave/C/node20.html
but not work, maybe i integrate this code in a bad mode!
Please, give me help...

Here is the code in main funciton:

Code:

struct dirent **namelist;
          char dir[100]="ms0:/MUSIC/Minutes to Midnight/";
          int b;
          int a=-1;
          int n;
          pspDebugScreenSetXY(0, 4);
          n = scandir(dir, &namelist, 0, alphasort);
          int file_select();
          b=n;
          if(n<0){
                   printf("Directory not found or error reading!");
                   }
          while(b--){
                      if(a!=n){     
                      a++;
                      printf("%s\n", namelist[a]->d_name);
                      }
                      }


int file_select(namelist)
 
      {if ((strcmp(namelist->d_name, ".") == 0) ||
                  (strcmp(namelist->d_name, "..") == 0))
                   return (FALSE);
            else
                        return (TRUE);
      }


Last edited by ne0h on Thu Mar 20, 2008 3:58 am; edited 1 time in total
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Mar 19, 2008 7:31 am    Post subject: Reply with quote

Please use the [ code ] [ /code ] bbs tags around any code you post. It makes it that much harder for folks if you don't as the formatting is removed, making the code hard to read.
Back to top
View user's profile Send private message AIM Address
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