我也遇到了类似的问题,为此我写了一个ahk脚本
(需要Gdip库编译)
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
编译完成后,我们可以使用CopyToClip.exe <your_file_path>
将文件内容复制到剪贴板,但目前只支持文本和图片。