Jump to content

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


Recommended Posts

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??

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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")

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

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.
 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

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...