Writes text to specific line in file and overwrite file data

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Writes text to specific line in file and overwrite file data

Post by newuser » Fri Aug 02, 2013 3:30 pm

Is it possible to implement these 2 functions below?

1) Writes text to a specific line in a file.

C:\text.txt contain
hello1
hello2
hello3
hello4
hello5

Eg, write>Bye,3,C:\text.txt
Write Bye to c:\text.txt line number 3.
Then result

C:\text.txt now contain
hello1
hello2
Bye
hello4
hello5


2) Overwrite file with new text.

C:\text.txt contain
hello1
hello2
Bye
hello4
hello5

Eg, writefile>yeah,C:\text.txt
Overwrite c:\text.txt with text yeah.
Then result

C:\text.txt now contain
yeah

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sat Aug 03, 2013 5:26 pm

Yes it's possible.

Add text to specified line

Code: Select all

ReadFile>C:\text.txt,vAllText
//Read text at line 3
ReadLn>C:\text.txt,3,vTextAtLine
//Add text to line 3
StringReplace>%vAllText%,%vTextAtLine%,Bye%CRLF%%vTextAtLine%,vModifiedText
DeleteFile>C:\text.txt
WriteLn>C:\text.txt,r,vModifiedText
Overwrite File

Code: Select all

DeleteFile>C:\text.txt
WriteLn>C:\text.txt,r,yeah

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Sat Aug 03, 2013 5:43 pm

Thanks Rain, but I wanted it in commands like ReadFile, ReadLn, etc,
because I'm doing it in virtual mode(modifying those files in memory).
The CopyFile, WriteLn etc works in virtual mode because its native commands in MS.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Aug 05, 2013 5:49 pm

I'm not sure I follow. My example has ReadFile, ReadLn, WriteLn etc.

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Tue Aug 06, 2013 10:40 am

In virtual mode, cant create new files or delete existing files, but can modify existing files.

Thats why I need native ms commands to do it. Since ms native commands using something like/similar called api I think(not sure what you call it, Im not that familliar with those terms).

Eg. I have 2 files named file1.txt and file2.txt in virtual mode.
I can use CopyFile>file1.txt,file2.txt function, it will copy file1.txt contents and overwrite into file2.txt contents in virtual mode.

But I cant use dos xcopy or copy commands to do it, because these commands need physical files(reside on hard disk), it cant work in virtual mode.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts