Jump to content

Updating a text file with the content of an exsisting one


Recommended Posts

Hi All,

here is my concer :

In a specific folder , I have couple text file created automatically every day with a specific format "mmddyyyyF1.txt",mmddyyyyF2.txt"

I need to copy the contents of those created files and paste them at the end of an exsisting master files.

masterF1.txt , masterF2. that are in other folder.

Please help with the syntax i am really stuck here.

Thanks

Link to comment
Share on other sites

from help file, list of commands that will probably help y to finde your best sutible solution

FileReadLine

_FileWriteToLine

_FileReadToArray

_ArrayAdd

_FileWriteFromArray

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • Moderators

molay,

First, welcome to the AutoIt forums.

When you post here it always helps if you have had a go at solving your problems beforehand. Having some code to work on is a great help - and no-one here is too keen to help the "code it for me" brigade.

Reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here. Using the Search facility is also a good tip as there is a pretty good chance your question has been asked before. Look for the "Search" button to the right in the title bar .

In your case I would look carefully at FileRead and FileWrite. :-)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi M23,

Thanks for the quick Reply.

Sure i went through the Help which i find it very explicit and simple with the examples.For this specifc issue i was completely lost. I have to find how to copy the content of the txt file and copy it at last line of an exsisting one..

If you tell me that is in the help i will go back there to check ..

Thanks a gain and sorry for that.

Molay

Link to comment
Share on other sites

you already have what you need to get it to work

Pls post some codes so that we see what did y try so that anyone can help you with your script.

what you need is posible to do with this commands

_FileReadToArray to read first file and to read second file

_ArrayAdd to add lines from first array to second array

_FileWriteFromArray to rewrite all the data from second array to document

with fileread&write it si posible but it will b to slow if your working with alot of lines in document.

so pls post some codes first, so that we can all see where y have problem and what did y try to do.

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • Moderators

molay,

A one-time good deal! This assumes your files are text based - if we are talking binary we need to adjust a bit.

FileRead will read the contents of the small files mmddyyyyF1/2.txt by using this:

$sFile_Contents = Fileread("file_path")

Then you add the contents to your "master" file by using this:

FileWrite("master_file_path", $sFile_Contents)

If you have problems, do as bogQ suggests and post the code that is not working. It is always easier to work when you have something to get your teeth into! (Can you tell I have just had dinner?)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

hi Guys,

thanks for your help. I habe been able to have iot working correctly. But what when the 1nd file is updated i am having like indexed number in the header of the file.

Is there a way to remove those numbers. here is my Code :

#include <file.au3>

#include <Array.au3>

;Read the first File ----------------------------------------------------------------

Dim $aRecords

$file1 = "C:\Test1.txt"

If Not _FileReadToArray($file1,$aRecords) Then

;MsgBox(4096,"Error", " Error reading text file to Array error:" & @error)

Exit

EndIf

For $x = 1 to $aRecords[0]

;Msgbox(0,'Record:' & $x, $aRecords[$x])

Next

;-----------------------------------------------------------------------------------

; Read The 2nd File

Dim $bRecords

$file2 = "C:\Test2.txt"

If Not _FileReadToArray($file2,$bRecords) Then

;MsgBox(4096,"Error", " Error reading text file to Array error:" & @error)

Exit

EndIf

For $x = 1 to $bRecords[0]

;Msgbox(0,'Record:' & $x, $bRecords[$x])

Next

;-------------------------------------------------------------------------------------

; Add lines from the 2nd file to the end of the 1st one

For $i = 1 to $aRecords[0]

_ArrayAdd($bRecords, $aRecords[$i])

;_ArrayAdd($bRecords, $aRecords[$i+1])

;_ArrayAdd($bRecords, $aRecords[$i+2])

;_ArrayDisplay($bRecords, "$avArray AFTER _ArrayAdd()")

;Msgbox(0,'Record:' & $x, $bRecords[$x])

Next

;_ArrayDisplay($bRecords, "$avArray AFTER _ArrayAdd()")

_FileWriteFromArray($file2, $bRecords, 0)

and here is what i am getting in the file 2 " test2.tct "

5

1

2nd field

1st Update.

2nd update.

3rd Update.

1st Update.

2nd update.

3rd Update.

I need to remove the 5 & 1

Any idea ?

thanks

Link to comment
Share on other sites

  • Moderators

molay,

From that ever useful Help file for _FileReadToArray : "Remarks: $aArray[0] will contain the number of records read into the array".

So you need to get rid of the [0] element of the array once it has been created. And before you ask, _ArrayDelete will do that for you.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If you are just attempting to append the contents of one file to the existing contents then why are you playing with arrays at all?

$hFile = FileOpen($masterFile, 1)
FileWrite($hFile, @CRLF & FileRead($newFile))
FileClose($hFile)

EDIT: Better yet, just to make sure you don't append it a dozen times while you are playing with it.

If Not StringInStr(FileRead($MasterFile), FileRead($newFile)) Then
    $hFile = FileOpen($masterFile, 1)
    FileWrite($hFile, @CRLF & FileRead($newFile))
    FileClose($hFile)
EndIf
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...