Create new txt file containing clipboard contents

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
kiwichick
Posts: 738
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Create new txt file containing clipboard contents

Post 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.
Windows 10 Pro 22H2
Scaling 150%

admin
Site Admin
Posts: 67269
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Create new txt file containing clipboard contents

Post by admin »

Edit / Paste Special / Paste Text Into File

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Create new txt file containing clipboard contents

Post by LittleBiG »

Code: Select all

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

kiwichick
Posts: 738
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Create new txt file containing clipboard contents

Post by kiwichick »

Thanks LittleBiG, That command didn't even occur to me :veryconfused:
Windows 10 Pro 22H2
Scaling 150%

kiwichick
Posts: 738
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Create new txt file containing clipboard contents

Post 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.
Windows 10 Pro 22H2
Scaling 150%

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create new txt file containing clipboard contents

Post by highend »

When you've highlighted it (by sel()), did you place the focus on the correct pane?
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 738
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Create new txt file containing clipboard contents

Post 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'.
Windows 10 Pro 22H2
Scaling 150%

kiwichick
Posts: 738
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Create new txt file containing clipboard contents

Post by kiwichick »

I still cannot figure out how to make the selection work. Please help!!
Windows 10 Pro 22H2
Scaling 150%

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create new txt file containing clipboard contents

Post by highend »

Then show us your code?
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 738
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Create new txt file containing clipboard contents

Post 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?
Windows 10 Pro 22H2
Scaling 150%

admin
Site Admin
Posts: 67269
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Create new txt file containing clipboard contents

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

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create new txt file containing clipboard contents

Post 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
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 67269
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Create new txt file containing clipboard contents

Post by admin »

Thanks for the Help hint.

kiwichick
Posts: 738
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Create new txt file containing clipboard contents

Post 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 :?
Windows 10 Pro 22H2
Scaling 150%

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Create new txt file containing clipboard contents

Post 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
One of my scripts helped you out? Please donate via Paypal

Post Reply