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 

Help to copy file

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



Joined: 24 Aug 2007
Posts: 88

PostPosted: Mon Oct 01, 2007 3:45 am    Post subject: Help to copy file Reply with quote

Hi

Can somebody help me to COPY (not replace) a file from ms0 to another place on ms0?

And also how to create a directory (if dircetory not exsits)

Thanks !
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Mon Oct 01, 2007 4:13 am    Post subject: Reply with quote

*gets out C book*

Well making a directory you can do, mkdir(dir, 0777);

And copying do (minus any sort of error handling):
Code:

FILE* in; FILE *out;
char buf[1024];
size_t len;

in = fopen(in, "rb");
out = fopen(out, "wb");
len = fread(buf, 1, 1024, in);
while(len > 0) {
   fwrite(buf, 1, len, out);
   len = fread(buf, 1, 1024, in);
}

fclose(in); fclose(out);

Really you should learn basic C libraries first :)
Back to top
View user's profile Send private message
Question_dev



Joined: 24 Aug 2007
Posts: 88

PostPosted: Mon Oct 01, 2007 4:15 am    Post subject: Reply with quote

Can i also use this :

Code:
int fileCopy(char* inSrc, char* inDest) {
     SceUID tempSrc = sceIoOpen(inSrc, PSP_O_RDONLY, 0777);
     if(!tempSrc)
          return -1;
     SceUID tempDest = sceIoOpen(inDest, PSP_O_WRONLY | PSP_O_CREAT, 0777);
     if(!tempDest) {
          sceIoClose(tempSrc);
          return -2;
     }

     char tempData[1024];
     int tempRead = sceIoRead(tempSrc, tempData, 1024);
     int tempWritten;

     while(tempRead > 0) {
          tempWritten = sceIoWrite(tempDest, tempData, tempRead);
          if(tempWritten != tempRead) {
               sceIoClose(tempDest);
               sceIoClose(tempSrc);
               sceIoRemove(inDest);
               return -3;
          }
          tempRead = sceIoRead(tempSrc, tempData, 1024);

     }

     sceIoClose(tempDest);
     sceIoClose(tempSrc);

     return 1;
}


and to copy then :

Example

Code:
fileCopy("ms0:/PSP/GAME/File.no", "ms0:/PSP/File.no");


EDIT : Yes i've tested it and it works!
Back to top
View user's profile Send private message
2.6,CRACKED!



Joined: 26 Jul 2007
Posts: 18

PostPosted: Tue Oct 02, 2007 2:14 am    Post subject: Reply with quote

Then why ask in the first place, especially if your copying and pasting
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