|
-
Mar 7th, 2010, 03:31 PM
#1
Thread Starter
Lively Member
[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!
-
Mar 7th, 2010, 04:02 PM
#2
Lively Member
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
-
Mar 7th, 2010, 04:13 PM
#3
Thread Starter
Lively Member
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
-
Mar 7th, 2010, 06:09 PM
#4
Lively Member
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
-
Mar 7th, 2010, 06:47 PM
#5
Thread Starter
Lively Member
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
-
Mar 7th, 2010, 07:20 PM
#6
Thread Starter
Lively Member
Re: Automating text file name
Great, Got it working with IO.File.Exists thanks again.
Tags for this Thread
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
|