Delete directorys and their content
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.
-
- Posts: 376
- Joined: Wed May 10, 2006 11:31 pm
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 ;)
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: Select all
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);
}
Thanks! :D and if anyone wants it, the psp version:
Code: Select all
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);
}
You'll almost certainly want
in there. Often the random stuff in dirent means sceIoDread() will fail.
Jim
Code: Select all
memset(&dirent, 0, sizeof dirent);
Jim