I also encountered a similar problem, for which I wrote an ahk script
(requires Gdip library to compile)
CopyToClip.ahk:
fileName := %0%
if( !FileExist(fileName) )
{
MsgBox, %fileName% not found!
return
}
;MsgBox, %fileName%
file := FileOpen(fileName, "r")
if( ErrorLevel )
{
MsgBox, Open %fileName% error!
return
}
encoding := File.Encoding
fileSize := File.Length
; Read as text?
readAs := "unkonw"
SplitPath, fileName, name, dir, ext, name_no_ext, drive
if( ext == "txt" || ext == "md" || ext == "bat" || ext == "cmd" || ext == "ahk" || ext == "ini" || ext == "sfo")
{
readAs := "text"
}
else if( ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "xbt" || ext == "img" )
{
readAs := "image"
}
else if( fileSize > 10240 )
{
MsgBox, Unsupport file size %fileSize%
return
}
else
{
ToolTip, Unsupport file type %ext%`, but read as text.
readAs := "text"
}
;MsgBox, %readAs%
if( readAs == "text" )
{
fileContent := File.Read()
Clipboard := fileContent
}
else if( readAs == "image" )
{
pToken := Gdip_Startup()
Gdip_SetBitmapToClipboard(pBitmap := Gdip_CreateBitmapFromFile(fileName))
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
;file.RawRead(fileContent, fileSize)
}else
{
MsgBox, Unkonw Error!
return
}
if( ErrorLevel )
{
MsgBox, Read %fileName% error!
return
}
ToolTip, %fileName%`nSize: %fileSize%
Sleep, 400
ExitApp
After compiling, we can use CopyToClip.exe <your_file_path>
to copy the contents of the file to the clipboard, but currently only supports text and image.