Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone,

I've to update 'date' on application. But this thing has to be done by DOS prompt not in Visual Studio. So what files I need to create? what should be the code?

Please help!


Cheers,
Rishu Mehra
Posted
Comments
CHill60 4-Feb-15 8:27am    
What do you mean by update 'date'? The timestamp of the executable or something else?
Rishu Mehra 4-Feb-15 8:46am    
Basically I am a newbie developer.
I need to update 'date' in a text file where $ [parameter] = "[date]" is given.
So a script file which automatically find all these txt files and update the current date in them at this area or parameter.
CHill60 4-Feb-15 11:03am    
Sorry - actually within the text file itself? I misunderstood. I'll update my solution

1 solution

See this article on TechNet[^]
Further information available.

This link[^] provides a script for updating text within a file using VBScript. There is an annoying pop-up on that site so I will reproduce the post here...Note I have not tested this personally.

waitely wrote:
If you want to edit a specific line in a file through VBScript you can use something like below. This reads the original file line by line and writes it out to a temporary file. If the original line meets the condition you want, make the changes required. At the end, close both files, delete the original and move the temp file.

VB
Const ForReading=1  
Const ForWriting=2  
Set objFSO = CreateObject("Scripting.FileSystemObject")  
folder = "C:\Program Files\Vendor\"  'change this to your folder
filePath = folder & "file.txt"  'change this to your filename
Set myFile = objFSO.OpenTextFile(filePath, ForReading, True)  
Set myTemp= objFSO.OpenTextFile(filePath & ".tmp", ForWriting, True)  
Do While Not myFile.AtEndofStream   
    myLine = myFile.ReadLine   
    If InStr(myLine, "Variable=") Then      'Change this to how you know where the date is
        myLine = "Variable="&whatever   'Change this to your [date]
    End If     
    myTemp.WriteLine myLine  
Loop  
myFile.Close  
myTemp.Close  
objFSO.DeleteFile(filePath)  
objFSO.MoveFile filePath&".tmp", filePath
 
Share this answer
 
v2
Comments
Rishu Mehra 5-Feb-15 4:19am    
This looks fine.. But one more thing which I just noticed. How can i change date as 'DD/MM/YY' in myFile instead of creating myTemp files.
CHill60 5-Feb-15 6:20am    
The tmp file is just there to write out to so that if anything goes wrong you still have your original. When you have successfully written out the .tmp file (with the new date), close both files, delete the original and rename the .tmp file to the same as the original.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900