Welcome! Log In Create A New Profile

Advanced

Change file extention on SD

Posted by pokeglobe 
Change file extention on SD
May 24, 2009 11:16AM
I am looking for a code that will change the extension of my %s file to %s.whatever
from .txt :)

Also when I try to read html from my server I get a code dump. so help would be appreciated.
Re: Change file extention on SD
May 24, 2009 11:45AM
int rename(const char *, const char*) is a standard c library function you can probably use to get the job done.. You'd use it like this:


// purpose: rename myfile.txt to myfile.tx_

#include stdio.h           // Angle brackets dont work with code tags, unless there's some escape character I don't know about

int main(int argc, char *argv[])
{
     if(!rename("myfile.txt", "myfile.tx_"))  // rename returns -1 on error EDIT: forgot a "
     {
          printf("file operation did not complete successfully\n");
          return 1;
     }
     
     printf("file operation completed successfully\n");
     return 1;
}

You'll need to use an absolute path to the file instead of just "myfile.txt" or you can do what I always do and just change your cwd


curdir = argv[0];   // do this in the scope of your main() function, or pass a pointer to your arguments to another function

	for(i = strlen(curdir); i >= 0; i--)
	{
		if (curdir == '/')
		{
			curdir[i+1] = '\0';
			break;
		}
	}

	chdir(curdir);

       // the above will change your current working directory to the directory your "boot.dol" is in...




Edited 3 time(s). Last edit at 05/24/2009 11:56AM by MrPeanut.
Re: Change file extention on SD
May 28, 2009 11:37PM
By the way, this is only tangentially related, but I see it in every thread so I figured I'd point it out. You can replace the < and > in your import statements with &lt; and &gt; which are the html entities for < and >, and it should show up properly. I'm not sure why the forum software doesn't automatically do an html entities encode so as to not lose the brackets as it comes up in every thread. There might be some problems that that could cause that I'm not seeing right now but they should be minor.
Eg:
import &lt;stdio.h&gt;
becomes
import <stdio.h>

It is a pain, but since you mentioned the html entities I figured I'd help out.
Sorry, only registered users may post in this forum.

Click here to login