AutoHotKey-Skript ersetzt umgekehrte Schrägstriche durch Schrägstriche

434
msoutopico

Ich führe einen Linux-Emulator (oder ein Subsystem) unter Windows 10 aus, und manchmal muss ich Windows-Pfade in der Linux-Konsole vorbeigehen. Windows-Pfade verwenden Backslashes \, um Verzeichnisse zu trennen, während Linux-Pfade stattdessen Schrägstrich / verwenden.

Um zu vermeiden, das \ mit / manuell ersetzen zu müssen, habe ich versucht, ein AHK-Skript zu verwenden, um den Pfad, den ich kopiere, zu ersetzen. Dies funktioniert jedoch nicht.

Dies ist mein Skript (ich habe im Code ##works until here##den entferntesten Punkt markiert, an dem es scheinbar funktioniert):

^+7:: ; Ctrl+Shift+7 (/)  ;Empty the Clipboard. Clipboard = ;Copy the select text to the Clipboard. SendInput, ^c ;Wait for the Clipboard to fill. ClipWait  ;Perform the RegEx find and replace operation, ;where the needle is what we want to replace. haystack := Clipboard needle := "\" replacement := "/" result := RegExReplace(haystack, needle, replacement)  ;Empty the Clipboard Clipboard = ;Copy the result to the Clipboard. Clipboard := result ;##works until here## ;Wait for the Clipboard to fill. ClipWait   ;-- Optional: -- ;Send (paste) the contents of the new Clipboard. SendInput, %Clipboard%  ;Done! return 

Vielen Dank im Voraus für alle Tipps.

0

1 Antwort auf die Frage

0
msoutopico

Es scheint, dass der Backslash nicht erkannt werden muss, um von RegExReplace erkannt zu werden.

needle := "\\"