Create new txt file containing clipboard contents
Posted: 18 Sep 2012 11:05
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.
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
Code: Select all
writefile("clip.txt", "<clipboard>");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 RenameAhem, did anybody see my post? This is built in since many years ago.admin wrote:Edit / Paste Special / Paste Text Into File
Read the help entry for writefile()?Now my next question is, I have writefile set to rename on collision so how would I make selectitems apply to the renamed file?
So you can get the (modified) name via a gettoken on the variable name.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
The return value should be: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
5|E:\Test\a\K\a-01.txt
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 havehighend wrote:So you can get the (modified) name via a gettoken on the variable name.
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