Page 1 of 2

Create new txt file containing clipboard contents

Posted: 18 Sep 2012 11:05
by kiwichick
Hi there, I know I'm probably missing something really obvious but how would I create a new text file that contains the current contents of the clipboard? Cheers.

Re: Create new txt file containing clipboard contents

Posted: 18 Sep 2012 11:24
by admin
Edit / Paste Special / Paste Text Into File

Re: Create new txt file containing clipboard contents

Posted: 18 Sep 2012 11:25
by LittleBiG

Code: Select all

writefile("clip.txt", "<clipboard>");

Re: Create new txt file containing clipboard contents

Posted: 18 Sep 2012 12:38
by kiwichick
Thanks LittleBiG, That command didn't even occur to me :veryconfused:

Re: Create new txt file containing clipboard contents

Posted: 27 Sep 2012 01:05
by kiwichick
Hi again, When the text file is created what is the code to have it selected for rename like the 'new' command parameter? I can get the file selected (highlighted) but not for rename (as in pressing F2). Cheers.

Re: Create new txt file containing clipboard contents

Posted: 27 Sep 2012 04:50
by highend
When you've highlighted it (by sel()), did you place the focus on the correct pane?

Re: Create new txt file containing clipboard contents

Posted: 27 Sep 2012 06:45
by kiwichick
Hi highend, I can't remember what I tried but I know I didn't use a focus command. And I think I tried using 'selectitems' and not 'sel'.

Re: Create new txt file containing clipboard contents

Posted: 29 Sep 2012 11:40
by kiwichick
I still cannot figure out how to make the selection work. Please help!!

Re: Create new txt file containing clipboard contents

Posted: 29 Sep 2012 11:42
by highend
Then show us your code?

Re: Create new txt file containing clipboard contents

Posted: 29 Sep 2012 12:11
by kiwichick
Sorry highend, I kept deleting the code I was trying and starting again :oops: But about 2 minutes after I posted I found some code in another thread and now, YAY, I have this working:

Code: Select all

writefile("new text file.txt", "<clipboard>", r);
   focus(list);
   #485; //F5   Refresh File List
   sel 1; selectitems "new text file.txt";
   #172; //F2   Rename
Now my next question is, I have writefile set to rename on collision so how would I make selectitems apply to the renamed file?

Re: Create new txt file containing clipboard contents

Posted: 29 Sep 2012 12:13
by admin
admin wrote:Edit / Paste Special / Paste Text Into File
Ahem, did anybody see my post? This is built in since many years ago.

Re: Create new txt file containing clipboard contents

Posted: 29 Sep 2012 12:23
by highend
Now my next question is, I have writefile set to rename on collision so how would I make selectitems apply to the renamed file?
Read the help entry for writefile()?
Usage

WriteFile() is implemented as a function (instead of a statement) because the return value can be useful. You may, however, call functions without using a dummy variable. See examples below.

Example with on_exist = "r"

For example, if "a.txt" exists in the current folder, a new file "a-01.txt" is created if the Incremental Affix is "-01":

text writefile("a.txt", "ab", "r");

The text window will shown a return like this including the full filename. The "5" (1 OR 4) means "data written" and "file was renamed": 5|E:\Test\a\K\1-01.txt
So you can get the (modified) name via a gettoken on the variable name.

@Don
Small mistake in the help file
The text window will shown a return like this including the full filename. The "5" (1 OR 4) means "data written" and "file was renamed": 5|E:\Test\a\K\1-01.txt
The return value should be:
5|E:\Test\a\K\a-01.txt

Re: Create new txt file containing clipboard contents

Posted: 29 Sep 2012 17:32
by admin
Thanks for the Help hint.

Re: Create new txt file containing clipboard contents

Posted: 30 Sep 2012 02:04
by kiwichick
highend wrote:So you can get the (modified) name via a gettoken on the variable name.
Sorry highend, I've had a look at gettoken in the help file but I can't see how I apply it to the script I already have :?

Re: Create new txt file containing clipboard contents

Posted: 30 Sep 2012 02:49
by highend

Code: Select all

$fileName = "new text file.txt";
   $modFileName = writefile($fileName, "<clipboard>", r);
   $fileName = (gettoken($modFileName, 2, "|") != "") ? gettoken($modFileName, 2, "|") : $fileName;
   focus(list);
   #485; //F5   Refresh File List
   sel 1; selectitems $fileName;
   #172; //F2   Rename