Writing text files with incrementing filenames

Results 1 to 5 of 5

Thread: Writing text files with incrementing filenames

  1. #1
    Ed Kay Guest

    Default Writing text files with incrementing filenames

    Hi<BR><BR>I have a system that generates and displays quotes dependent on the criteria the user puts in a form. In order that they can then e-mail the quote to themselves, print it without graphics, or move to the next stage I decided to write each generated quote to a new text file and store it for future manipulation. However, I don&#039;t want to use application variables, so how can I name the quote.txt files incrementally ie.quote1, quote2, quote3 etc? Is there a way to look into the folder and find the last file?<BR><BR>Though I am sure it would be easier, the reason I don&#039;t want to use application level variables is that my ISP is notoriously unreliable. If I set up some variable arrays to store these increments, wouldn&#039;t they all be reset to zero if the server went down?<BR><BR>Any help or advice you can offer would be most gratefully appreciated...<BR><BR>Many thanks - Ed<BR>

  2. #2
    Bill Spurling Guest

    Default RE: Writing text files with incrementing filenames

    Ed,<BR>You do this by looping through all the files<BR>1) Create you fileSystemObject<BR>2) set MyFolder = Object.GetFoler(Path)<BR>3) Loop through files<BR>for each thing in MyFolder.Files<BR>counter = counter + 1<BR>next<BR>4) Increment counter again<BR>5) Create your file using the new counter as the filename<BR>6) Kill your objects<BR><BR>Hope this helps you some<BR><BR>Bill<BR><BR>

  3. #3
    Ed Kay Guest

    Default RE: Writing text files with incrementing filenames

    Many thanks for that Bill - a simple and elegant solution - i will certainly give it a try...<BR><BR>cheers!

  4. #4
    Join Date
    Dec 1969

    Default Problem

    While this would work wonderfully in a single-user environment, remember that multiple Web requests can be handled virtually simultaneously. So what happens if 3 folks hit the site at the same time? They&#039;ll each get the same folder id. Ugh.<BR><BR>One thing you can do is use Application.Lock / Application.UnLock around such code, which would have the effect of serializing that portion of code so that only one user could execute it at a time...<BR><BR>One thing you could do is use a database... any chances of that? IDENEITY columns have autoincrementing values that are guaranteed to be unique. Let the DB worry about the concurrency issues and whatnot.

  5. #5
    Ed Kay Guest

    Default RE: Problem

    That&#039;s a very good point, Scott - thanks for bringing it to my attention. I think you are right and I&#039;m now working on using the database option since that way I can also keep track of whether the quote has been printed or emailed etc...<BR><BR>Cheers for the feedback!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts