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] Recursive delete...
Goto page 1, 2  Next
 
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: Thu Jun 12, 2008 9:48 pm    Post subject: [SOLVED] Recursive delete... Reply with quote

Hi,
I've find this recursive function to delete a directory, but when I try to delete a big dir (PSP) , it was deleted all the MS!!
I've try to modify it but it's not perfect!
I think there are a basically solution, but I'haven't find it!
What's wrong in this function?
It's a possible bug of sceIoRmDir or sceIoDelete funct?

Code:

void RmDir(char *dir)
{
 SceIoDirent dirent;
 int fd;
 char fullname[512];
 fd = sceIoDopen(dir);
 memset(&dirent, 0, sizeof dirent);
 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)
      {
             RmDir(fullname);
             sceIoRmdir(fullname);
         }
  else
      {
      sceIoRemove(fullname);
      }
  }
 sceIoDclose(fd);
 sceIoRmdir(dir);
}


I think the problem is in the string fullname and in it's allocate ( not perfect english I think)
_________________
Get Xplora!


Last edited by ne0h on Sat Jun 14, 2008 12:43 am; edited 2 times in total
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Thu Jun 12, 2008 10:28 pm    Post subject: Reply with quote

What you call a big dir?

A directory with lots of files in it, or a directory with a really long name?
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Jun 12, 2008 10:33 pm    Post subject: Reply with quote

Oh come on ! your wonderful function is not even slightly recursive. Is it so hard to think by yourself instead of gibbering ?
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Jun 12, 2008 10:46 pm    Post subject: Reply with quote

This function is not my, I've searched and I've find this!
I call big dir a directory with a lot of dir and files
_________________
Get Xplora!
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Jun 12, 2008 10:49 pm    Post subject: Reply with quote

This function is not my, I've searched and I've find this!
I call big dir a directory with a lot of dir and files
hilde, I haven't understand your post!
Explain your problem please!
_________________
Get Xplora!
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Thu Jun 12, 2008 11:13 pm    Post subject: Reply with quote

Hint: Your function is named RmDir().

Internally it's calling recursiveDelete()

Spot the difference.

That's what hlide meant by it not being recursive.

If you want to rename functions, ensure you rename all of them!
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 12:56 am    Post subject: Reply with quote

Excuse me,
I've writed bad the fuct ( the old func is named recursivedelete, but in my prog i've changed the name to RmDir)
However thanks but this is not the error
_________________
Get Xplora!
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Fri Jun 13, 2008 1:03 am    Post subject: Reply with quote

ne0h wrote:
Excuse me,
I've writed bad the fuct ( the old func is named recursivedelete, but in my prog i've changed the name to RmDir)
However thanks but this is not the error


if so, why to remove a directory twice ? kinda fishy your excuse...

Code:
void RmDir(char *dir)
{
 SceIoDirent dirent;
 int fd;
 char fullname[512];
 fd = sceIoDopen(dir);
 memset(&dirent, 0, sizeof dirent);
 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)
      {
             RmDir(fullname);
             >>>sceIoRmdir(fullname);<<<
         }
  else
      {
      sceIoRemove(fullname);
      }
  }
 sceIoDclose(fd);
 >>>sceIoRmdir(dir);<<<
}
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 1:12 am    Post subject: Reply with quote

yes, it's a error but this is not my problem
_________________
Get Xplora!


Last edited by ne0h on Fri Jun 13, 2008 2:49 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: Fri Jun 13, 2008 1:21 am    Post subject: Reply with quote

You need to watch recursive functions - their greatest fault is the amount of stack space they consume. Look at ONE thing in the function:

Code:
 char fullname[512];


Every recursion will consume that much stack space. If a dir has a thousand files, it will consume a thousand times the stack space. Make sure you have a BIG stack when using functions like this.
Back to top
View user's profile Send private message AIM Address
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 1:25 am    Post subject: Reply with quote

Ok, this is not the error but I've try to resolve it yet:

Code:

int Rmdir(char *dir)
{
    SceIoDirent dirent;
    int fd;
    fd = sceIoDopen(dir);
    memset(&dirent, 0, sizeof dirent);
    char *fullname=(char*)malloc(1);
    free(fullname);
    while (sceIoDread(fd, &dirent) > 0)
    {
        fullname=(char*)malloc(strlen(dir)+strlen(dirent.d_name)+1);
        sprintf(fullname, "%s/%s", dir, dirent.d_name);
        if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
        {
             Rmdir(fullname);
             sceIoRmdir(fullname);
        }
        else
        {
             sceIoRemove(fullname);
        }
    }
    sceIoDclose(fd);
    sceIoRmdir(dir);
    return 0;
}

I've writed it speedly, I think is not perfect! ( For memory use )
_________________
Get Xplora!
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Fri Jun 13, 2008 1:30 am    Post subject: Reply with quote

RmDir("ms0:/blabla") will call :
>RmDir("ms0:/blabla/bloblo");
>>sceIoRmdir("ms0:/blabla/bloblo"); // just after sceIoDclose(fd);
>sceIoRmdir("ms0:/blabla/bloblo"); // just after RmDir(fullname);
>sceIoRmdir("ms0:/blabla"); // just after sceIoDclose(fd);

Now, who's the idiot ?
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 1:32 am    Post subject: Reply with quote

What? Excuse me, maybe I'm a idiot but I haven't understand your post!
_________________
Get Xplora!
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Fri Jun 13, 2008 1:33 am    Post subject: Reply with quote

not a surprise
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 1:34 am    Post subject: Reply with quote

hlide, if I want delete a folder named "FOLDER", I think if I don't write the final sceIoRmDir the dir will be not deleted
J.F., I think the memory it's not the problem, because if I try yet to delete a big directory the PSP crash!
_________________
Get Xplora!
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Fri Jun 13, 2008 1:45 am    Post subject: Reply with quote

well i guess C is not your forte
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 1:48 am    Post subject: Reply with quote

bah
_________________
Get Xplora!


Last edited by ne0h on Fri Jun 13, 2008 2:47 am; edited 2 times in total
Back to top
View user's profile Send private message
Question_dev



Joined: 24 Aug 2007
Posts: 88

PostPosted: Fri Jun 13, 2008 2:01 am    Post subject: Reply with quote

I know a site where you can find a del dir example.
http://www.pspcoding.co.nr

Goto Coding Examples -> C/C++ Examples

Hope this helps.
Cu
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 2:08 am    Post subject: Reply with quote

But what's wrong in my function?
I want know the bug if is possible!
_________________
Get Xplora!
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 2:10 am    Post subject: Reply with quote

Yeah, maybe I've resolved!
Code:

int Rmdir(char *dir)
{
    SceIoDirent dirent;
    int fd;
    fd = sceIoDopen(dir);
    memset(&dirent, 0, sizeof dirent);
    char *fullname=(char*)malloc(1);
    free(fullname);
    while (sceIoDread(fd, &dirent) > 0)
    {
        fullname=(char*)malloc(strlen(dir)+strlen(dirent.d_name)+1);
        sprintf(fullname, "%s/%s", dir, dirent.d_name);
        if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
        {
             Rmdir(fullname);
             sceIoRmdir(fullname);
        }
        else
        {
             sceIoRemove(fullname);
--------->memset(&dirent, 0, sizeof dirent);
        }
    }
    sceIoDclose(fd);
    sceIoRmdir(dir);
    return 0;
}

_________________
Get Xplora!


Last edited by ne0h on Fri Jun 13, 2008 2:12 am; edited 1 time in total
Back to top
View user's profile Send private message
Question_dev



Joined: 24 Aug 2007
Posts: 88

PostPosted: Fri Jun 13, 2008 2:11 am    Post subject: Reply with quote

Compare the two.

If you can't find it by yourself, then you need to learn c.

Also, ever heard about google? "c delete dir"

Cu
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 2:13 am    Post subject: Reply with quote

... I've already resolved!
I've posted before read the other example!
Thanks, Question_dev!
_________________
Get Xplora!
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Fri Jun 13, 2008 2:22 am    Post subject: Reply with quote

"I've already resolved! " is your motto ? it sounds quite repetive to my ears... and unnecessary to say
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 2:24 am    Post subject: Reply with quote

I've writed this funct but this uses all the RAM!!!!
Why?
Code:

int Rmdir(char *dir)
{
    SceIoDirent dirent;
    int fd;
    fd = sceIoDopen(dir);
    memset(&dirent, 0, sizeof dirent);
    while (sceIoDread(fd, &dirent) > 0)
    {
        char fullname[strlen(dir)+strlen(dirent.d_name)+1];
        sprintf(fullname, "%s/%s", dir, dirent.d_name);
        if ((FIO_S_IFREG & (dirent.d_stat.st_mode & FIO_S_IFMT)) == 0)
        {
             Rmdir(fullname);
             sceIoRmdir(fullname);
        }
        else
        {
             sceIoRemove(fullname);
             memset(&dirent, 0, sizeof dirent);
        }
    }
    sceIoDclose(fd);
    sceIoRmdir(dir);
    return 0;
}

_________________
Get Xplora!
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 2:37 am    Post subject: Reply with quote

Thanks!...
_________________
Get Xplora!


Last edited by ne0h on Fri Jun 13, 2008 2:43 am; edited 1 time in total
Back to top
View user's profile Send private message
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Fri Jun 13, 2008 2:42 am    Post subject: Reply with quote

I lol'd at this thread.
@ne0h, make sure you learn some C coding before saying hlide is an idiot and does not know C and is more stupid than you. I believe hlide has a lot more C experience than you.
Also, it's not "I've writed", writed does not exists.
I'ts I've written or I wrote. (at least this is what I know from my english lol)

@Question Dev, maybe google will not be his best friend for coding lol and I think you are not the right person to say "SEARCH" as you were like him a few months ago.

Edit, don't bump your posts please. Wait for an answer if you even deserve one.
_________________

Upgrade your PSP
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 2:46 am    Post subject: Reply with quote

bah...
I have understand what hlide intend to say yet...
_________________
Get Xplora!


Last edited by ne0h on Fri Jun 13, 2008 2:50 am; edited 1 time in total
Back to top
View user's profile Send private message
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Fri Jun 13, 2008 2:50 am    Post subject: Reply with quote

It's I haven't understood. (irregular verb)
he meant you were trying to delete the same directory after it was deleted.
Code:
             RmDir(fullname);
             sceIoRmdir(fullname);

you run your RmDir function to delete the folder then you run sony's function to delete the folder, again.

Do you understand?
_________________

Upgrade your PSP
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Jun 13, 2008 2:52 am    Post subject: Reply with quote

yes, yes, I have understand...
_________________
Get Xplora!
Back to top
View user's profile Send private message
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Fri Jun 13, 2008 2:52 am    Post subject: Reply with quote

ok, now how do you know your function is using all the ram?
_________________

Upgrade your PSP
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
Goto page 1, 2  Next
Page 1 of 2

 
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