Jump to content

Read entire txt file & copy/paste


Recommended Posts

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

Link to comment
Share on other sites

  • 3 weeks later...
  • 8 months later...
  • 1 year later...

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

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

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

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