To get you started, here is the updated code that will copy content of any selected file to clipboard
Option Explicit
Function OnClick(ByRef ClickData)
Dim fso, tfile, txt
If ClickData.func.sourcetab.selected_files.Count > 0 Then
Set fso = CreateObject("Scripting.FileSystemObject")
Set tfile = fso.OpenTextFile(ClickData.func.sourcetab.selected_files(0))
txt = tfile.ReadAll
DOpus.SetClip txt
End If
End Function
[Script code updated, as per the next post below. --Leo]
Oops, replace the
If Len(ClickData.func.sourcetab.selected_files) > 0 Then
with
If ClickData.func.sourcetab.selected_files.Count > 0 Then
otherwise the script would throw error when nothing is selected
[Script code in the previous post has been edited and updated to include this change. --Leo]
Ok guys, thanks for help.
fkast
June 25, 2023, 3:01pm
17
Hello. Is there a way to paste contents of certain file (ex., C:\1.txt) as new .txt files in {s}?
lxp
June 25, 2023, 3:09pm
18
How would that be different from making a copy of 1.txt
?
fkast
June 25, 2023, 3:20pm
19
i want to copy its contents. for ex., file 1.txt contains this lines:
Directory Opus 1
Directory Opus 2
Directory Opus 3
...
Directory Opus 1000
i want to create 1000 new .txt files, a copy of "FileType NEW=.txt FROMCLIPBOARD" command, but from file, not clipboard...
I have test this code but it's doesn't works for me. where is my mistake?
I have select a .txt file and press this button. then open MS Word and press Ctrl+v. But its doesn't paste the text from the selected files.
Leo
June 25, 2023, 5:59pm
21
fkast:
i want to create 1000 new .txt files, a copy of "FileType NEW=.txt FROMCLIPBOARD" command, but from file, not clipboard...
That’s just a simple file copy which you can do via the copy command.
fkast
June 25, 2023, 7:00pm
22
sorry, guys. just verified all COPY's arguments, but not found a suitable one.
Leo
June 25, 2023, 7:58pm
23
What’s this got to do with “copy file contents to clipboard” from 8 years ago? The clipboard isn’t involved if you’re just trying to make a second copy of a file somewhere.
Please start new threads for new questions. I’ve had to ask a few times now.
Leo
June 25, 2023, 10:09pm
24
It would only include the first file, and only if it's a text file.
I just tried it and it still works OK today.
fkast
June 26, 2023, 12:44am
25
it seemed to me that this topic is the closest to my question. very close...
Leo
June 26, 2023, 12:47am
26
It's really not. You don't want to do anything to the clipboard. You want to copy a file from one place to another. Please start a new thread if you want help with that.
abcd.txt (7.6 KB)
Copy Content.dcf (988 Bytes)
Here is my test file and button it's still not work here.
lxp
June 26, 2023, 12:58pm
28
The FileSystemObject can't handle your file's encoding.
This might work better:
Examples:
Send the contents of the specified file to the clipboard.
CopyContent c:\test.txt
Send the contents of the file with the extension txt in the specified folder to the clipboard.
CopyContent c:\temp PATTERN *.(txt|vbs) FILEINFO TRIM
Send…
lxp
June 26, 2023, 1:19pm
29
Or use this script:
// https://resource.dopus.com/t/copy-file-contents-to-clipboard/21051
function OnClick(clickData) {
var tab = clickData.func.sourcetab;
if (tab.selected_files.count == 0) return;
var stt = DOpus.Create().StringTools();
DOpus.SetClip(stt.Decode(tab.selected_files(0).Open().Read(), 'auto'));
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
<label>21051</label>
<icon1>#newcommand</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/copy-file-contents-to-clipboard/21051</instruction>
<instruction />
<instruction>function OnClick(clickData) {</instruction>
<instruction> var tab = clickData.func.sourcetab;</instruction>
<instruction> if (tab.selected_files.count == 0) return;</instruction>
<instruction> var stt = DOpus.Create().StringTools();</instruction>
<instruction> DOpus.SetClip(stt.Decode(tab.selected_files(0).Open().Read(), 'auto'));</instruction>
<instruction>}</instruction>
</function>
</button>
1 Like
lxp
October 22, 2023, 7:51am
32
@khalidhosain @galaxyhub
The script has always worked here. Try replacing auto
with utf-16-le
. Maybe your system locale settings somehow confuse the StringTools.
1 Like
lol - that yields chinese text, using utf-8
works. Many thanks.
1 Like