sree161

is there any method to copy text from existing notepad to new notepad????

18 posts in this topic

#1 ·  Posted

is there any method to copy text from existing notepad to new notepad????
i have many lines of text in one note pad. i need to copy one line into a notepad and close it. i need to copy 2nd line into another notepad and close it.
Is there any way to do it??

Share this post


Link to post
Share on other sites



#2 ·  Posted

Yes. Look at FileRead, ClipGet, and ClipPut in the help file. There are a number of ways to skin that particular cat; all of them with examples in the help file.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks as i am new to autoit i dont know much.....i will go through them and get back for further quires...

Share this post


Link to post
Share on other sites

#4 ·  Posted

do i need to open that file to be read.....??

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

in the help program they are creating a temp file to read data from....but i already have a file with data from which it should be read.......how can i read data from specific file on my local.
i tried this by giving location of my local at which data is there but no use...kindly assist me.

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
$FileRead = FileRead("C:\Users\asdf\Desktop\not.txt")
MsgBox(0, "OTPT", "$FileRead")

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

1. FileRead will open the file to read it. If you are doing a lot or repetitive steps in a file, you can use FileRead, so your script is not constantly opening and closing the file in question

2. Take off the quotes around $FileRead in your msgbox

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted

i tried it and i am not getting any ouput in msg box...
do i need to enter any specific count value...because my text to be copied is in alpha numeric format??
code used:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
$FileRead = FileRead("C:\Users\asdf\Desktop\not.txt")
MsgBox(0, "OTPT", $FileRead)

not.txt contains:
1.xxxxxxxxxxxxxxx
2.xxxxxxxxxxxxxxx
3.xxxxxxxxxxxxxxx
4.xxxxxxxxxxxxxxx
5.xxxxxxxxxxxxxxx

Share this post


Link to post
Share on other sites

#8 ·  Posted

I am confused.  Do you want to copy not.txt to a new text file on disk? Or do you want to read the contents of file not.txt and then... paste it into another text file? Much of muchness it seems.  

First solution would be FileCopy

; Copy Au3 files in the temporary directory to a new folder/directory called Au3Files.
    FileCopy("c:\myautoit\not.txt", "c:\myautoit\new.txt", $FC_OVERWRITE + $FC_CREATEPATH)

 

1 person likes this

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

#9 ·  Posted

but i wanted to copy specific data from existing file to a new one.
so i thought if i could first read the specific data in the file, i could copy the same data.
Any other ways to proceed.??

Share this post


Link to post
Share on other sites

#10 ·  Posted

What specific data? How do you identify that specific data?  Post a sample?


Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

#11 ·  Posted

ya like i have 5 lines in a notepad.
i want to copy line 1 to one notepad and save it.
                        line 2 to notepad2 and save it.
but all these should not make changes in master notepad.
 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Still no example.

Will it always be line 1?  Where does line 1 go? to new1.txt?  and line 2?  Will it always be line 2?  Where does it go? Also into new1.txt or into new2.txt?

Copy without changing the source is really not a problem.  The problem is identifying the exact data to copy, and then the destination.

Have you looked in the Help file under FileReadLine ?

Your questions sound something like "I don't know where I'm going but I hope to be there soon..."

You need help, be more specific

Edited by Skysnake

Skysnake

Why is the snake in the sky?

Share this post


Link to post
Share on other sites

#13 ·  Posted

To be more specific
my master notepad contains:
1.xxxxxxxxxxxxxxxxxxx
2.xxxxxxxxxxxxxxxxxxxxxxxxxx
3.xxxxxx
4.xxxxxxxxx
5.sadfhhshakj

These are fixed and won't keep changing.

Now i want to copy "1.xxxxxxxxxxxxxxxxxxx" to new1.txt
                                 "2.xxxxxxxxxxxxxxxxxxxxxxxxxx" to new2.txt                 and so on till line 5.

Share this post


Link to post
Share on other sites

#14 ·  Posted

can ClipPut and ClipGet be helpful ???
if yes how can i i use them??
how can i clip specific data from text file

Share this post


Link to post
Share on other sites

#15 ·  Posted

is there any reason you want use notepad ?
you can read from a master file and write lines in new files directly

#include <FileConstants.au3>
Local $sLineRead = "", $x = 0
Local $sFilePath = "MasterFile.txt"

; Open the file for reading and store the handle to a variable.
Local $hFileOpen = FileOpen($sFilePath, $FO_READ)

Do
    ; Read a line from the file using the handle returned by FileOpen.
    $sLineRead = FileReadLine($hFileOpen)
    If @error Then Exit ; if no more lines in master file then exit

    $x += 1
    ; write previously read line to a new file
    FileWrite("NewFile" & $x & ".txt", $sLineRead)

Until @error ; if problem on writing then end

 

2 people like this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#16 ·  Posted

There is no specific reason for using notepad.
Anyways thanks for helping me.....i am able to get the text i want
Thank you very much

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Hi all
Now i am trying to append text to the notepad while creating itself. I am using FileWriteLine() to append text Below is the program i used.

#include <FileConstants.au3>
Local $sLineRead = "", $x = 0
Local $sFilePath = "C:\Users\asdf\Desktop\not.txt"

Local $hFileOpen = FileOpen($sFilePath, $FO_READ)

Do
    $sLineRead = FileReadLine($hFileOpen)
    If @error Then Exit
    $x += 1
    FileWrite($sLineRead & $x & ".txt", $sLineRead)
    FileWriteLine($sLineRead)
    FileWriteLine($sLineRead, "Line1:")
    FileWriteLine($sLineRead, "Line2:")
    FileWriteLine($sLineRead, "Line3:")
    FileWriteLine($sLineRead, "Line4:")
Until @error ;

 

i am getting output but it is creating 2 files. one is .txt file and other with no extension(file format).
Is my logic right??
Is there any other command to append text.??
Kindly help

Edited by sree161
wrong location

Share this post


Link to post
Share on other sites

#18 ·  Posted

You can try:

#include <File.au3>

;~ Path for New1.txt, New2.txt etc...
Local $sFileSave = @ScriptDir
;~ File Name to Read
Local $sFileRead = @ScriptDir & "\Notepad.txt"

Local $aFileRead, $hFileOpen
_FileReadToArray($sFileRead, $aFileRead)
For $i = 1 To $aFileRead[0]
    ;~ This will create the new file + path (if it doesn't exist), using append mode
    $hFileOpen = FileOpen($sFileSave & "\New" & $i & ".txt", 9)
        ;~ Write line to new file with new line at the end
        FileWrite($hFileOpen, $aFileRead[$i] & @CRLF)
    ;~ Close the File
    FileClose($hFileOpen)
Next

 

2 people like this

Share this post


Link to post
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