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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving a text file from one path to another with timestamp

Status
Not open for further replies.

dalex17

Technical User
Jul 14, 2002
96
US
Good afternoon,

I need assistance with a VB code that will copy a .txt file from one location to another.

The catch is, however, that I need the copied .txt (that is, the new .txt file that copied into another location), to end with a time stamp. Here is an example of what I mean:

P:\files\summary.txt save as P:\files\final\summary1205200312:20p.m.txt

I hope this makes sense but please let me know if I can further explain.

Much apreciation,

dalex

 
dim fso as new filesystemobject
dim ts as textstream
dim mystring as string

set ts=fso.opentextfile("myfile.txt",reading)
myString=ts.readall
ts.close

set ts=fso.opentextfile(app.path & "/" & Now,for writing)
ts.write mystring
ts.close

bb
 
Thanks Bigger brother,

Could you clarify where my new path should be typed in your second statement beggining with set ts (after the first ts close).

Thank you!
 
app.path is the folder location of the .exe file you are currently running. Replace this with any folder location, but enclose it with quotations.

BB
 
BB,

This is what I have. I get an error on the second part below beggining with Set ts

Also, whay did you write ".exe file I am currently running" My objective to copy a text file to anther location. Thanks again.



Dim fso As New filesystemobject
Dim ts As textstring
Dim mystring As String

Set ts = fso.opentextfile("P:\Standard Reports\Acct\Bank\PP File.txt", reading)
mystring = ts.readall
ts.Close

Set ts=fso.opentextfile("P:\Standard Reports\Acct\Bank\PP History" & "/" & Now,for writing)
ts.write mystring
ts.Close

End Sub
 
Sorry, try this..

Set ts=fso.opentextfile("P:\Standard Reports\Acct\Bank\PP History\summary" & Now & ".txt", forwriting)
ts.write mystring
ts.Close

BB
 
Thank you BB, however it now does not like:

fso As New filesystemobject


dalex
 
you need to make a refernce to the ms scripting runtime. This can be found in the project -> references menu.

This should fix this.

BB
 
Could you point to where Projects->references is located? I do not see it in Projects Explorer...
 
on the main title menu bar. It should be one of the main menu options. I thought it was in projects, but it may not be. I think it is the third menu after file, and references is one of the bottom options available.

MS scripting runtime is then in alphabetical order.

BB
 
Without referencing anything you could simply use this...

FileCopy "P:\files\summary.txt", "P:\files\final\summary" & Now & ".txt"

Why reference something like FSO when there is absolutely no need to?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top