I frequently have to copy file paths from Windows 10 programs or dialogue boxes into my R
code. Since R
escapes backslashes, I always have to change the backslashes to forward slashes or double backslashes, so I am trying to program this problem away so that anytime I copy text and then use some special combination of shortcut keys to paste, it replaces my backslashes with double backslashes. So for example, if I copied "C:\windows\system32\drivers\etc" and then pressed some combination of keys like Ctrl+Alt+P (or even using the right click context menu) I'd like to change the pasted output to "C:\\windows\\system32\\drivers\\etc" instead of what was copied. I thought I might be able to do this in PowerShell with something like this:
$copiedtext = Get-Clipboard;
$copiedtext = -join(-join('"', $copiedtext -replace "\\", '\\'), '"');
Set-Clipboard $copiedtext;
Write-Output $copiedtext | clip
But that only outputs my clipboard to the console (and doesn't work if I assigne a shortcut to my PowerShell program and assign shotcut keys to it). Can anyone recommend how to modify this to achieve what I want or recommend some other language that would allow Windows to always recognize some shortcut key combination of characters as my special paste operation? I'd like to do this without having to start up the program when I want to use it too, if possible.