Jump to content

Copying Links Into A new txt doc


Recommended Posts

Hey forum

Was wondering if something like this was possible or not.

I have a txt doc with words. So far i'm able to read each line of txt and copy them to the clipboard.

I would like to take that copied line and paste it into a new txt doc, but inserted in between a middle of a sentence.

is this possible? If so how/what should i look through to achieve this?

ex:

txt doc has:

red

blue

green

want to create new doc:

my favorite color is (pasted word here). what is yours?

then save as a new document

- repeat the process

something along this example is what i'm trying to achieve.

Any help or insight would be greatly appreciated.

Edited by augustspies
Link to comment
Share on other sites

A simple approach:

FileClose(FileOpen("c:\txt.doc", 2))            ;creates a new file with an empty content
FileWrite("c:\txt.doc", "my favorite color is "&ClipGet()&". what is yours?")
ShellExecute("c:\txt.doc")

Pay attention when you want to generate new files - you will need a different name with every FileClose(FileOpen statement.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

A simple approach:

FileClose(FileOpen("c:\txt.doc", 2))            ;creates a new file with an empty content
FileWrite("c:\txt.doc", "my favorite color is "&ClipGet()&". what is yours?")
ShellExecute("c:\txt.doc")

Pay attention when you want to generate new files - you will need a different name with every FileClose(FileOpen statement.

appreicate the response enaiman. I gave it a go and it works.

I just added it to the script that copies the each line & and I see what you mean by needing a different name. Is it possible to have it number the files in incremental order?

I'm thinking I need to do a - For,Next loop, but unsure where/how to incorporate it into the script. Is that the right thinking?

Here's what I have below:

Local Const $File = @ScriptDir & "\test.txt"

Global $Handle = FileOpen($File, 0)
If $Handle = -1 Then
    MsgBox(0x10, 'Error', 'Could not open the file:' & @LF & $File)
    Exit
EndIf

HotkeySet('^{RIGHT}', 'NextLine')
HotkeySet('{ESC}', 'Done')

NextLine()

While 1
    Sleep(0x7FFFFFFF)
WEnd

Func NextLine()
    Local $NextLine = FileReadLine($Handle)
    If @Error Then
        MsgBox(0x40, 'End of File', 'The end of the file has been reached.', 10)
        Done()
    EndIf
    ClipPut($NextLine)
    TrayTip('Copied to Clipboard', $NextLine & @LF & @LF & 'Ctrl+Right: Next line' & @LF & 'Esc: Quit', 5, 1)
    FileClose(FileOpen(@scriptdir & "\destination" & "\test.txt", 1))            ;creates a new file with an empty content
    FileWrite(@scriptdir & "\destination" & "\test.txt", "my favorite color is "&ClipGet()&". what is yours?")
    ShellExecute(@scriptdir & "\destination" & "\test.txt")
EndFunc

Func Done()
    FileClose($Handle)
    Exit
EndFunc
Link to comment
Share on other sites

Not difficult to achieve at all - just declare a counter as a global variable and everytime the function is executed, use the counter in the filename and ... increment the counter :)

Like this:

Local Const $File = @ScriptDir & "\test.txt"
Global $FileCounter = 1
Global $Handle = FileOpen($File, 0)
If $Handle = -1 Then
    MsgBox(0x10, 'Error', 'Could not open the file:' & @LF & $File)
    Exit
EndIf

HotkeySet('^{RIGHT}', 'NextLine')
HotkeySet('{ESC}', 'Done')

NextLine()

While 1
    Sleep(0x7FFFFFFF)
WEnd

Func NextLine()
    Local $NextLine = FileReadLine($Handle)
    If @Error Then
        MsgBox(0x40, 'End of File', 'The end of the file has been reached.', 10)
        Done()
    EndIf
    ClipPut($NextLine)
    TrayTip('Copied to Clipboard', $NextLine & @LF & @LF & 'Ctrl+Right: Next line' & @LF & 'Esc: Quit', 5, 1)
    FileClose(FileOpen(@scriptdir & "\destination" & "\test"&$FileCounter&".txt", 1))            ;creates a new file with an empty content
    FileWrite(@scriptdir & "\destination" & "\test"&$FileCounter&".txt", "my favorite color is "&ClipGet()&". what is yours?")
    ShellExecute(@scriptdir & "\destination" & "\test"&$FileCounter&".txt")
    $FileCounter += 1
EndFunc

Func Done()
    FileClose($Handle)
    Exit
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Not difficult to achieve at all - just declare a counter as a global variable and everytime the function is executed, use the counter in the filename and ... increment the counter :)

Like this:

Local Const $File = @ScriptDir & "\test.txt"
Global $FileCounter = 1
Global $Handle = FileOpen($File, 0)
If $Handle = -1 Then
    MsgBox(0x10, 'Error', 'Could not open the file:' & @LF & $File)
    Exit
EndIf

HotkeySet('^{RIGHT}', 'NextLine')
HotkeySet('{ESC}', 'Done')

NextLine()

While 1
    Sleep(0x7FFFFFFF)
WEnd

Func NextLine()
    Local $NextLine = FileReadLine($Handle)
    If @Error Then
        MsgBox(0x40, 'End of File', 'The end of the file has been reached.', 10)
        Done()
    EndIf
    ClipPut($NextLine)
    TrayTip('Copied to Clipboard', $NextLine & @LF & @LF & 'Ctrl+Right: Next line' & @LF & 'Esc: Quit', 5, 1)
    FileClose(FileOpen(@scriptdir & "\destination" & "\test"&$FileCounter&".txt", 1))            ;creates a new file with an empty content
    FileWrite(@scriptdir & "\destination" & "\test"&$FileCounter&".txt", "my favorite color is "&ClipGet()&". what is yours?")
    ShellExecute(@scriptdir & "\destination" & "\test"&$FileCounter&".txt")
    $FileCounter += 1
EndFunc

Func Done()
    FileClose($Handle)
    Exit
EndFunc

sweet enaiman :) I appreciate your time helping me out

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