[RESOLVED] Automating text file name
I have a program, and writes data to a text file... with a template inside...
All works fine, and saves fine...
I'm wondering, how could I automate the filename it saves?
Currently it saves the text file as NewOrder.txt
I would like it to now realise that there is a NewOrder.txt already there, and save as NewOrder1.txt
Then when the program is closed, and I go to do a new one, it will say ok NewOrder2.txt
Hoping this is possible, I've been reading up on my.settings but I can't really find what I'm looking for...
Thanks! :thumb:
Re: Automating text file name
Dont really need to look at form .settings
You would need to maybe write a small function
take you base file name as string
add an integer
and add a loop using the System.IO.File.Exists component. if value is true then increase the integer by one
Then you can call your function in your save dialogue or streamwriter
Re: Automating text file name
Sounds lovely, any start on the code? I can't really understand that to be honest with you... Very very new to all of it :blush:
Re: Automating text file name
you could show us the code so far, and maybe change it simply at first so that you are using System.IO.File.Exists, if you google that you start to get some idea of how to implement it
Re: Automating text file name
I'll google that now sir! Thanks again...
vb Code:
Dim txtFile As String = IO.File.ReadAllText("template.txt")
txtFile = txtFile.Replace("[left eye]", LeftEyeTextBox.Text)
txtFile = txtFile.Replace("[right eye]", RightEyeTextBox.Text)
IO.File.WriteAllText("NewOrder.txt", txtFile)
That's my code though... but I'll read up on that now
Re: Automating text file name
Great, Got it working with IO.File.Exists thanks again.