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 

Delete directorys and their content

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



Joined: 17 Nov 2005
Posts: 51

PostPosted: Mon Oct 23, 2006 4:39 am    Post subject: Delete directorys and their content Reply with quote

Is there a function on the PSP to delete directorys and all the content in them? sceIoRmdir wont delete directories if they have files in them.
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Mon Oct 23, 2006 5:58 am    Post subject: Reply with quote

You need to delete the files within the directory first.

I have this code snippet that will delete all files and sub directories as well as the given directory, but it might not be perfect ;)

Code:
void recursiveDelete(char *dir)
{
 DIR *dip;
 struct dirent *dit;
 dip = opendir(dir);
 char fullname[512];

 while ((dit = readdir(dip)) != NULL)
 {
  sprintf(fullname, "%s/%s", dir, dit->d_name);

   if ((FIO_S_IFREG & (dit->d_stat.st_mode & FIO_S_IFMT)) == 0)
      {
             recursiveDelete(fullname);
             printf("Deleting directory: %s\n", fullname);
             rmdir(fullname);
         }
  else
      {
      printf("Deleting file: %s %i\n", fullname, FIO_S_IFREG & (dit->d_stat.st_mode & FIO_S_IFMT));
      remove(fullname);
      }
  }
 closedir(dip);
 rmdir(dir);
}
Back to top
View user's profile Send private message
pspwill



Joined: 17 Nov 2005
Posts: 51

PostPosted: Mon Oct 23, 2006 6:40 am    Post subject: Reply with quote

Thanks! :D and if anyone wants it, the psp version:
Code:

void recursiveDelete(char *dir)
{
 int fd;
 SceIoDirent dirent;
 fd = sceIoDopen(dir);
 char fullname[512];

 while (sceIoDread(fd, &dirent) > 0)
 {
  sprintf(fullname, "%s/%s", dir, dirent.d_name);

   if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
      {
             recursiveDelete(fullname);
             printf("Deleting directory: %s\n", fullname);
             sceIoRmdir(fullname);
         }
  else
      {
      printf("Deleting file: %s %i\n", fullname, FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT));
      sceIoRemove(fullname);
      }
  }
 sceIoDclose(fd);
 sceIoRmdir(dir);
}
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Mon Oct 23, 2006 7:41 am    Post subject: Reply with quote

You'll almost certainly want
Code:

memset(&dirent, 0, sizeof dirent);

in there. Often the random stuff in dirent means sceIoDread() will fail.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Oct 23, 2006 11:55 pm    Post subject: Reply with quote

Or just use Insert_witty_name's code, it uses newlib which takes care of that sort of stuff.
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