-
March 14th, 2018, 06:11 PM
#1
Create file, then increment by 1
Hey Guys,
I'm looking for some code that works as follows:-
I have a click box, whenever I press the button it creates a file in c:/results called results1.txt.
the second time I press the button, if the file results1.txt exists it creates a new file called results2.txt and so on increasing the number.
Would anybody be able to help please?
-
March 15th, 2018, 03:45 AM
#2
Re: Create file, then increment by 1
So what is your problem? Search for a file? Create a new file?
Something else?
Victor Nijegorodov
-
March 15th, 2018, 05:01 AM
#3
Re: Create file, then increment by 1
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 15th, 2018, 05:14 AM
#4
Re: Create file, then increment by 1
Originally Posted by Merlin_3000uk
...
I have a click box, whenever I press the button it creates a file in c:/results called results1.txt.
the second time I press the button, if the file results1.txt exists it creates a new file called results2.txt and so on increasing the number.
Would anybody be able to help please?
Some useful links:
https://msdn.microsoft.com/en-us/lib...or=-2147217396
https://msdn.microsoft.com/en-us/lib...or=-2147217396
Victor Nijegorodov
-
March 15th, 2018, 11:16 AM
#5
Re: Create file, then increment by 1
Originally Posted by VictorN
So what is your problem? Search for a file? Create a new file?
Something else?
Hey Victor,
What I'm looking to do is create a file, then if the file exists don't overwrite the old file but create a new file.
Each time the code runs it increases the file name to say "file.1.txt", "file.2.txt", "file.3.txt" each time creating a new file.
Thanks
Simon
-
March 15th, 2018, 01:09 PM
#6
Re: Create file, then increment by 1
Originally Posted by Merlin_3000uk
Hey Victor,
What I'm looking to do is create a file, then if the file exists don't overwrite the old file but create a new file.
Each time the code runs it increases the file name to say "file.1.txt", "file.2.txt", "file.3.txt" each time creating a new file.
Thanks
Simon
Well, again: what is the thing (exactly!) you cannot achieve?
Victor Nijegorodov
-
March 16th, 2018, 05:44 AM
#7
Re: Create file, then increment by 1
Originally Posted by Merlin_3000uk
Hey Victor,
What I'm looking to do is create a file, then if the file exists don't overwrite the old file but create a new file.
Each time the code runs it increases the file name to say "file.1.txt", "file.2.txt", "file.3.txt" each time creating a new file.
Thanks
Simon
... and see post #3!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|