Sign in to follow this  
Followers 0
augustspies

Read entire txt file & copy/paste

12 posts in this topic

Hi guys,

I found this script a couple days ago but don't remember the thread to reference it so I apologize in advance

This script reads 1 line @ a time and then copies it to the clipboard. Is it possible to take this script and make it so that it reads all the lines/entire content and then copies it to clipboard to be pasted somewhere? If so how could I do this?

Local Const $File = "D:\file.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)
EndFunc

Func Done()
    FileClose($Handle)
    Exit
EndFunc

Share this post


Link to post
Share on other sites



This puts the whole file content in the clipboard:

$File = "D:\file.txt"
ClipPut(FileRead($File))

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

Share this post


Link to post
Share on other sites

Hi augustspies,

HotkeySet('^{RIGHT}', '_doCopy')
HotKeySet('{ESC}', 'Done')

While 1
    Sleep(500)
WEnd

Func _doCopy()
    $message = "File to Copy in ClipBoard"
    $var = FileOpenDialog($message, @AppDataCommonDir & "", "Textfiles (*.txt;*.ini))", 1 + 2)
    If @error Then Return ;

    $sText = FileRead($var)
    ClipPut($sText)
    TrayTip('File is copied to Clipboard', $var & @crlf & 'Esc: Quit' & @CRLF & 'Ctrl-Right: Copy another File', 5, 1)
EndFunc   ;==>_doCopy

Func Done()
    Exit
EndFunc   ;==>Done

mfg autoBert

Share this post


Link to post
Share on other sites

This puts the whole file content in the clipboard:

$File = "D:\file.txt"
ClipPut(FileRead($File))

Thanks - those two lines of code have got me out of a mess I've been racking my brain on for the last hour or so....

Share this post


Link to post
Share on other sites

This puts the whole file content in the clipboard:

$File = "D:file.txt"
ClipPut(FileRead($File))

Thanks. I was also looking for this and thanks to you in my first post here

Share this post


Link to post
Share on other sites

If I get $File like this:

$File=FileRead($aXYZ,0)

ClipPut puts nothing in the clipboard.

Do you see how to overcome this?

Share this post


Link to post
Share on other sites

Well, it is almost Easter...

What is the value in $aXYZ?

Show your script including the clipput function.

Use code tags to post the script, please.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

If I get $File like this:

$File=FileRead($aXYZ,0)

ClipPut puts nothing in the clipboard.

Do you see how to overcome this?

You have used FileRead, but you have setted to 0 the number of characters to read. That's why you don't see nothing :P

BTW it's a good pratice to use the FileOpen handle in FileRead.

$File = @ScriptDir & "\MyFile.txt"
$Open = FileOpen($File, 0)
$Read = FileRead($Open)
ClipPut($Read)
FileClose($Open)

Hi!


My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites

You have used FileRead, but you have setted to 0 the number of characters to read.

Yes, of course, DUH!?!?


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Yes, of course, DUH!?!?

That happens, maybe is this easter time muttley

Hi!


My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites

Yes, waiting for brain ressurection...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Yes, waiting for brain ressurection...

[offtopic]That make me laughing out so loud :D [/offtopic]

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

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
Sign in to follow this  
Followers 0