Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

saving over existing .txt files

 
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: 24213
35
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!
 
Forget Steve. Look at this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!