| View previous topic :: View next topic |
| Author |
Message |
pspwill
Joined: 17 Nov 2005 Posts: 51
|
Posted: Mon Oct 23, 2006 4:39 am Post subject: Delete directorys and their content |
|
|
| 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 |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Mon Oct 23, 2006 5:58 am Post subject: |
|
|
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 |
|
 |
pspwill
Joined: 17 Nov 2005 Posts: 51
|
Posted: Mon Oct 23, 2006 6:40 am Post subject: |
|
|
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 |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Mon Oct 23, 2006 7:41 am Post subject: |
|
|
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 |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Mon Oct 23, 2006 11:55 pm Post subject: |
|
|
| Or just use Insert_witty_name's code, it uses newlib which takes care of that sort of stuff. |
|
| Back to top |
|
 |
|