• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Need script to insert current date into a csv file.

I have file.csv that has several entries, and at the end of each entry i want add the current date. There is a carriage return symbol like a box at the end of each entry, so I would want to add the date like so: "05/30/2006" before the carriage return symbol.

Can someone show me some code that would do that.
0
totalimpact
Asked:
totalimpact
  • 4
  • 3
1 Solution
 
BrianGEFF719Commented:
open "c:\myfile.csv" for input as #1
while not eof(1)
 line input #1, myStr
 myStr = right(myStr,len(myStr) - len(vbcrlf))
 myStr = myStr & " " & date & vbcrlf
 finalStr = finalStr & myStr
wend
close #1

open "c:\newcsv.csv" for output as #1
print #1, finalStr
close #1


Try something like that. Let me know if that helps you at all.

Brian
0
 
totalimpactAuthor Commented:
Is that a VB script? it is giving me an error:

Line: 1
Char: 25
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript Compilation error

My vbs file looks like so:

open "C:\TEST\test.csv" for input as #1
while not eof(1)
 line input #1, myStr
 myStr = right(myStr,len(myStr) - len(vbcrlf))
 myStr = myStr & " " & date & vbcrlf
 finalStr = finalStr & myStr
wend
close #1

open "C:\TEST\test.csv" for output as #1
print #1, finalStr
close #1
0
 
BrianGEFF719Commented:
Oh you're doing this in VB Script...

I honestly dont know that much about the FSO...sorry.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
totalimpactAuthor Commented:
What language was that in? it just has to work natively in windows.
0
 
BrianGEFF719Commented:
That was Visual Basic code...not VBScript. In VBScript you must use the File System Object.

Do you have a copy of Visual Basic, or an experience with Visual Basic?

Brian
0
 
totalimpactAuthor Commented:
Unfortunatley, I'm an IT guy, not a programmer, so I have next to nothing experience with scripting in general, asside from basic windows bat files.

I need this script for multiple Win XP machines so I would rather not install VB Runtime all over the place. So I need a VB, JS, or WS script that will parse the file and insert todays date at the end of every carriage return.

--anyone???
0
 
mvidasCommented:
totalimpact,

I'm writing this with the filename hardcoded, but if you'd like me to change it so it uses the csv file as an argument (either dragging the file into the .vbs or using SendTo) just let me know.  Paste the following into a text file, then save it with the extension .vbs:

 Dim FSO, TS, TempStr, TempArr(), Cnt, vFile
 Cnt = 0
 vFile = "C:\file.csv"
 Set FSO = CreateObject("scripting.filesystemobject")
 Set TS = FSO.OpenTextFile(vFile, 1) '1=ForReading
 Do Until TS.AtEndOfStream
  TempStr = TS.ReadLine
  ReDim Preserve TempArr(Cnt)
  TempArr(Cnt) = TempStr & "," & Date
  Cnt = Cnt + 1
 Loop
 TS.Close
 Set TS = FSO.OpenTextFile(vFile, 2) '2=ForWriting
 For Cnt = 0 To UBound(TempArr)
  TS.WriteLine TempArr(Cnt)
 Next
 TS.Close
 Set FSO = Nothing
 Set TS = Nothing
 Set TempStr = Nothing
 Set Cnt = Nothing
 Set vFile = Nothing

Make a copy of the .csv file first, as it doesn't seem to me that 'box' at the end of each line is a carriage return (if you're viewing it in notepad it shouldn't show up).  If it works out as you wanted, great, if not I can write a script to determine what that symbol is.

Brian - FSO is easy, and though it is better to do as you're doing when using VB, as you said we're stuck with FSO in VBS.  If you want to explore FSO a little more, you could always set a reference to Microsoft Scripting Runtime and play around in the object browser.  Very similar, though when working with binary files it is much easier to use Open in VB.

Matt
0
 
BrianGEFF719Commented:
>>Brian - FSO is easy, and though it is better to do as you're doing when using VB, as you said we're stuck with FSO in VBS.  If you want to explore FSO a little >>more, you could always set a reference to Microsoft Scripting Runtime and play around in the object browser.  Very similar, though when working with binary >>files it is much easier to use Open in VB.

Hi Matt,
Yah i've used FSO before I just dont use it enough to have the functions memorized. It would take me 45 minutes to write a hello world program i'd have to search for all the functions in MSDN :)


Brian
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now