Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I create a file even if file of the same name exists already?

Status
Not open for further replies.

mijulie

Programmer
Jun 21, 2001
36
0
0
IE
The data entered in the form is written to a textfile based on a combination of 2 variables. It is possible that there could be more than one file with the same 2 variables as another. If I save a file that already has the name then it overwrites the old one. Anyone know how to save every instance despite this?

Here is the code for creating the textfile based on the variables;

Set filesys = CreateObject("Scripting.FileSystemObject")
sub b1_onclick

Set filetxt = filesys.CreateTextFile("F:\Corktest\Sit\Cit\"&BuildForm.TheBinary.Value&BuildForm.TheBuild.Value&t, true)

I'd appreciate any help u can give me!

Mijulie
 
Well, you're not going to be able to save the file in the same directory with the same name... that's not possible. What you can do is use the .fileExists query of the fileSystemObject to first determine if there is already a file with that name in the directory, and then tack a number onto the end of the file name to go ahead and save it that way --

check out 's vbscript quick ref for more information on how to properly use the .fileExists method.

:)
Paul Prewett
penny.gif
penny.gif
 
You could delete the file, using the .DeleteFile Method, then create the file with .CreateTextFile...

or you could open the text file for writing, which by default overwrites everything in the file.

check out devguru.com for a concise reference on VBScript's file system object.

hope this helps
leo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top