Help to copy file

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Question_dev
Posts: 88
Joined: Fri Aug 24, 2007 8:23 pm

Help to copy file

Post by Question_dev »

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 !
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

*gets out C book*

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

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

Code: Select all

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 :)
Question_dev
Posts: 88
Joined: Fri Aug 24, 2007 8:23 pm

Post by Question_dev »

Can i also use this :

Code: Select all

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: Select all

fileCopy("ms0:/PSP/GAME/File.no", "ms0:/PSP/File.no");
EDIT : Yes i've tested it and it works!
2.6,CRACKED!
Posts: 18
Joined: Thu Jul 26, 2007 9:02 pm

Post by 2.6,CRACKED! »

Then why ask in the first place, especially if your copying and pasting
Post Reply