• Post Reply Bookmark Topic Watch Topic
  • New Topic

renaming a file with a filename that already exists  RSS feed

 
jin sun
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was wondering, how do you rename a file? And if there already is a file named that...how do you overwrite it and replace the file thats already there with the new file with the same name?

Sorry, I'm not sure whether this belongs to beginner or intermediate, please don't fine me!
[ June 15, 2005: Message edited by: jin sun ]
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may wish to check the API documentation for the "File" class; there's a method in there that can rename files.

whether or not it can rename files to a name which already exists isn't specified in those docs, unfortunately. the quick and easy way to find out would be to try it and see what happens, i suppose. but that's assuming that this behaviour isn't platform-dependent; it shouldn't be, but i can't be entirely certain.

even if it is platform-dependent, though, there is likely an easy work-around that will work everywhere. after all, if you're trying to rename a file "A" to be named "B", but another file named "B" already exists, what do you want to happen to the "B" that already exists? there are probably methods in the "File" class that can do that for you.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!