[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need script to insert current date into a csv file.

Posted on 2006-05-30
11
Medium Priority
?
221 Views
Last Modified: 2010-04-07
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
Comment
Question by:totalimpact
  • 4
  • 3
8 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 16794095
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
 

Author Comment

by:totalimpact
ID: 16794157
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 16794188
Oh you're doing this in VB Script...

I honestly dont know that much about the FSO...sorry.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:totalimpact
ID: 16794195
What language was that in? it just has to work natively in windows.
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 16794206
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
 

Author Comment

by:totalimpact
ID: 16794235
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
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 16798635
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 16800840
>>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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question