AHK can't recognize paths with space properly. Run("C:\Users\..\code.exe" "C:\Users\hello world.ahk) will open two files

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alawsareps
Posts: 38
Joined: 20 Jul 2016, 09:28

AHK can't recognize paths with space properly. Run("C:\Users\..\code.exe" "C:\Users\hello world.ahk) will open two files

27 Apr 2024, 05:37

it will open two files in VSCODE: "hello" and "world.ahk"

Code: Select all

#Requires AutoHotkey v2.0

f1:: { 
    
    Run("C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe " "C:\Users\jethr\OneDrive\Desktop\hello world.ahk")

}
what I want is:

Code: Select all

f1:: { 
    Send("^c") ; copy the file path
    sleep(100)
    Run("C:\Users\jethr\AppData\Local\Programs\Microsoft VS Code\Code.exe " A_Clipboard)
return
}

this only works fine with files with not spaces.
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: AHK can't recognize paths with space properly. Run("C:\Users\..\code.exe" "C:\Users\hello world.ahk) will open two f

27 Apr 2024, 06:13

Hello,

Paths with spaces must be quoted strings (as parameters), but you have passed unquoted strings as one parameter to your Run function. A MsgBox will help you to see the idea, as follows.

Code: Select all

#Requires AutoHotkey v2.0

F1:: {
 Static editor := EnvGet('LOCALAPPDATA') '\Programs\Microsoft VS Code\Code.exe'
 commandLine := editor ' "' A_Desktop '\hello world.ahk"'
 MsgBox commandLine
 Run    commandLine
 SoundBeep 1500
}
User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: AHK can't recognize paths with space properly. Run("C:\Users\..\code.exe" "C:\Users\hello world.ahk) will open two f

27 Apr 2024, 08:18

@alawsareps — You already asked and got an answer to basically the same question a little earlier here. Why are creating multiple threads asking the same questions? If you didn’t understand the answer in the earlier thread, follow up with another question in that thread. Don’t create a whole new thread.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: boardtc, DavidP, vanove and 55 guests