Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Find and rename content in csv via VBS

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-04-2012
Member
 
Join Date: Apr 2012
Location: Europe
Posts: 7
Find and rename content in csv via VBS
  

Hello.

I need to open CSV file, find some "string" in a row and rename it.

For example


Quote:
DATE;DEPART;CLASSE;SERVEUR;ERREURS;MESSAGE;SCHEDULE;TYP;DUREE;TAILLE(Kb);FICHIERS;RETENTION;WARS Date ouverture;WARS Date fermeture;Commentaires
2012-04-22;21:01:25;lala_nbondv02_data;nbondv02;0;the req ops;lmejvd-lala-2sem;lalaérentielle;00:12:53;1909225;1447;2 Sem
2012-04-22;21:00:00;lala_nbondv02_sys;nbondv02;0;the req ops;lmmjvd-lala-2sem;lalaérentielle;00:03:58;371778;2184;2 Sem
2012-04-22;21:00:59;lala_nbondv03_data;nbondv03;0;OK;lmejvd-lala-2sem;lalaérentielle;00:07:49;892604;6695;2 Sem
2012-04-22;21:00:00;lala_nbondv03_sys;nbondv03;0;OK;lmmjvd-lala-2sem;lalaérentielle;00:08:38;1209603;399;5 Sem
2012-04-22;21:00:57;lala_nbondv04_data;nbondv04;0;OK;lmejvd-lala-2sem;lalaérentielle;03:22:41;135497795;300;2 Sem
And I need to find string "the req ops" and change it for "OK"

Is it possible ?

I have some part of the code but not sure how to modify it.


Code:
Function OK()

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Rapport.csv", ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    If InStr(strLine, "the req ops") Then
        InStr(strLine, "OK")
    End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("C:\Rapport.csv", ForWriting)

objFile.Write strNewContents
objFile.Close

End Function

but it failing... could you help ?

Reply With Quote
  #2  
Old 08-06-2012
Member
 
Join Date: Jan 2006
Posts: 605
Re: Find and rename content in csv via VBS

Test the below code and your problem will be solved:

Code:
Const ForReading = 1 
Const ForWriting = 2  
strFileName = "C:\Rapport.csv" 
strOldText = "the req ops" 
strNewText = "OK" Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objFile = objFSO.OpenTextFile(strFileName, ForReading) 
strText = objFile.ReadAll 
objFile.Close strNewText = Replace(strText, strOldText, strNewText) 
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting) 
objFile.WriteLine strNewText 
objFile.Close
Reply With Quote
  #3  
Old 12-06-2012
Member
 
Join Date: Apr 2012
Location: Europe
Posts: 7
Re: Find and rename content in csv via VBS

Quote:
Originally Posted by janos™ View Post
Test the below code and your problem will be solved:

Code:
Const ForReading = 1 
Const ForWriting = 2  
strFileName = "C:\Rapport.csv" 
strOldText = "the req ops" 
strNewText = "OK" Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objFile = objFSO.OpenTextFile(strFileName, ForReading) 
strText = objFile.ReadAll 
objFile.Close strNewText = Replace(strText, strOldText, strNewText) 
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting) 
objFile.WriteLine strNewText 
objFile.Close
Thank you.

I'll check this
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Find and rename content in csv via VBS"
Thread Thread Starter Forum Replies Last Post
Where can I find Content.MSO folder The-Farmer MS Office Support 3 17-01-2014 09:03 AM
Cannot find content.ie5 on Windows 7 Delightful. Operating Systems 5 30-04-2011 10:35 AM
Cannot find downloadable content for Dragon Age 2 Danger Dengue Video Games 4 11-03-2011 03:08 AM
Unable to find Online code in Dead space 2 for bonus content intoxicating Video Games 4 01-02-2011 09:32 AM
How to find similar Webpage content in Firefox? abigial_i Technology & Internet 5 12-02-2010 07:42 AM


All times are GMT +5.5. The time now is 11:19 PM.