• Post Reply Bookmark Topic Watch Topic
  • New Topic

saving over existing .txt files  RSS feed

 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, I have an app that saves a new .txt file, it works fine, but it overwrites any .txt that is already in that folder with the same name (as it should) What I would like to know is if there is a way that I can make it so that the name of the new .txt file that I am creating has a (1) at the end of the file name i.e. example(1).txt if there is already a file with the same name.
thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Of course, there's a race condition -- after you come up with the unique name, another file by that same name may still be created.
 
sander hautvast
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use the File object, it has an exists() method.
with that you can check for the existence of a file. enough for an answer?
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys thats great!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!