Windows 7, Pfade mit Schrägstrich statt Backslash anzeigen

Windows 7, Pfade mit Schrägstrich statt Backslash anzeigen

Ich suche nach einer Möglichkeit, Windows dazu zu bringen, die Pfade immer als Schrägstriche statt als Backslashes darzustellen, um mir beim Kopieren und Einfügen von Pfaden in Java-Code viel Aufwand zu ersparen.

Um es klarer zu machen, möchte ich die Standarddarstellung wie folgt:

Standardmäßiges Explorer-Verhalten

so sein:

Gewünschtes Explorer-Verhalten

Wie kann ich das machen? Ich bin für jede Hilfe sehr dankbar, denn es macht mich wahnsinnig.

Antwort1

VerwendenPfad kopieren kopierenSoftware:

Screenshot der Unix-Pfadkopie

Aktivieren Sie in den Einstellungen die Option zum Kopieren des UNIX-Pfads.

Pfad kopieren Kopiereinstellungen Screenshot

Antwort2

Ich habe es so implementiert, wie Ankit es vorgeschlagen hat. Die Implementierung wurde etwas kniffliger, da der neu geschriebene Pfad nicht mehr zum Einfügen der eigentlichen Datei (nicht des Pfads als Text) verwendet werden kann. Ich habe dies umgangen, indem ich Situationen erkannt habe, in denen vermutlich nur die Textdarstellung verwendet wird. Technisch gesehen wäre es, so wie ich die Implementierung der Windows-Zwischenablage verstehe, sogar möglich, nur die Textdarstellung des Pfads zu ändern, aber diese Aufgabe überlasse ich jemand anderem. Ich bin nicht sicher, ob das mit AutoHotKey möglich ist.

Aus diesem Grund wurde das AutoHotKey-Skript für den folgenden Arbeitsablauf geschrieben:

  1. Tun Sie, was Sie normalerweise tun, um einen Pfad zu kopieren.
  2. Wir versuchen, das Notwendige zu tun, um einen sauberen Pfad in der Zwischenablage zu haben.
  3. Wenn wir es nicht standardmäßig tun können (wir wissen nicht, ob es gespeichert ist), tun wir nichts und Sie müssen den Pfad in der Zwischenablage manuell durch Drücken Shiftvon + Super+ bereinigen C.

Einzelheiten entnehmen Sie bitte dem Code:

#SingleInstance force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetTitleMatchMode, RegEx

;; Use this until I hit the first issue then document here and set back to default value.
SetDefaultMouseSpeed, 0

;; Copy clean file/directory path to clipboard (use forward slashes as file separators) {{{
;; https://stackoverflow.com/questions/1589930/so-what-is-the-right-direction-of-the-paths-slash-or-under-windows/1589959#1589959

;; WARNING: This clipboard substitution has the issue that after the substitution, pasting the file does not work anymore!!
;; Because of this, we don’t run the substitution OnClipboardChange globally but only when we consider it save and otherwise using a (manual) shortcut.
;; Situations where we know it is save:
;; * Double Commander calls CopyFullNamesToClip.
;; * Location bar in Explorer has focus. See limitations below!

;; The expected workflow is:
;; 1. Do what you usually do to copy a path.
;; 2. We try to do what is necessary to have a clean path in the clipboard.
;; 3. If we cannot do it by default (we don’t know that it is save), we do nothing and you have to manually make the path in the clipboard clean by pressing Shift+Super+C.

;; Ref: Get-CleanPath in ../../MS_Shell/Modules/ypidDotfiles/ypidDotfiles.psm1
;; Seems up to and including Windows 10, UNC paths with forward slashes don’t work.
;; At least //files.example.org/home and \\files.example.org/home and //files.example.org\home don’t work.
clean_path_in_clipboard() {
    If (RegExMatch(Clipboard, "^(?i)(?:[a-z]:)?\\[^\\]")) {
        StringReplace, Clipboard, Clipboard,\,/, All
    }
    Return
}

;; Shift+Super+C | Clean file/directory path in clipboard {{{
+#C::
    ; ClipSaved := ClipboardAll
    ; Clipboard = 

    ; Send ^c
    ;; Ensure that we are only working on text.
    ; ClipWait

    ; currentPath =
    ; WinGetClass explorerClass, A
    ; ControlGetText currentPath, Edit1, ahk_class %explorerClass%
    ; msgbox %currentPath%

    ; If (ErrorLevel) {
    ;     Clipboard := ClipSaved
    ;     MsgBox, 48, Clipboard copy warning, Failed to copy to clipboard.
    ;     Return
    ; }

    clean_path_in_clipboard()
Return
;; }}}

;; Shift+Alt+C | Hook Double Commander calls to CopyFullNamesToClip and run clean_path_in_clipboard afterwards.
;; We can "safely" do this because when CopyFullNamesToClip is called, the user wants to copy the path as text.
#UseHook
#IfWinActive ahk_exe doublecmd.exe
+!c::
    Send +!c
    clean_path_in_clipboard()
Return
#IfWinActive
#UseHook off

OnClipboardChange:
    ;; Fix file path when in transit in Explorer (or Double Commander).
    ;; Ensure that we are only working on text.
    If (WinActive("ahk_exe (?i)(?:explorer.exe|doublecmd.exe)") and A_EventInfo == 1) {

        ;; Location bar in Explorer has focus.
        ;; Run clean_path_in_clipboard after copying text to clipboard in Explorer when cursor is above "Location bar" known as Edit1 (bad programming/variable naming M$??).
        ;; Technically this is not 100 % bulletproof because you could do the copy to clipboard with Ctrl+L followed Ctrl+C while the cursor focuses some other control.
        If (WinActive("ahk_exe (?i)(?:explorer.exe)")) {
            MouseGetPos, , , , control_below_cursor
            If (control_below_cursor == "Edit1") {
                clean_path_in_clipboard()
            }
        }

        ;; We cannot do this globally, see WARNING above.
        ; clean_path_in_clipboard()
    }
return

;; }}}

(Dies wird auch auf GitHub verfolgt:https://github.com/ypid/dotfiles/blob/master/windows/neo-vars/source/custom.ahk)

Vielen Dank auch an Katharsas für die Feedback-Anfrage unter „Feedback Hub App für Windows 10“. Native Unterstützung wäre wünschenswert, aber ich glaube nicht, dass Microsoft das in einem angemessenen Zeitrahmen tun wird. Also müssen wir es einfach selbst mit dieser Art von Hacking tun. Schrägstriche sind der bessere plattformübergreifende Pfadtrenner. Lassen Sie sich niemals etwas von Microsoft vorschreiben. Viel Spaß ;-)

Antwort3

Führen Sie die folgende Funktion in PowerShell aus:

function slash {
    Get-Clipboard | 
    % {$_ -replace '\\','/'} |
    Set-Clipboard ; echo 'Conversion done.'
}

Dann können Sie es verwenden, indem Sie die Pfade kopieren und slashin Powershell ausführen.

Dies ist zwar kein direkter Weg, funktioniert aber, wenn Sie es nur für kurze, kontinuierliche Sitzungen benötigen und keine Anwendungen von Drittanbietern installieren möchten.

Antwort4

Dies kann durch die Verwendung eines Skripts erreicht werden, das auf die Zwischenablage zugreifen kann. Es funktioniert folgendermaßen:

  • Wählen und kopieren Sie den Pfad, der enthält \.
  • Drücken Sie eine beliebige Tastenkombination, um das Skript zu aktivieren.
  • Dieses Skript greift auf den Inhalt der Zwischenablage zu und ersetzt mithilfe einer einfachen Logik jedes Vorkommen von \durch /.
  • Jetzt enthält der Inhalt der Zwischenablage einen Pfad mit /.

Skript kann einCHARGEDatei oder eineAutoHotKeySkript. Aber ich glaube nicht, dass ein Bat auf den Inhalt der Zwischenablage zugreifen kann. Daher ist Autohotkey die beste Option.

verwandte Informationen