Page 1 of 1

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

Posted: 27 Apr 2024, 05:37
by alawsareps
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.

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

Posted: 27 Apr 2024, 06:13
by mikeyww
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
}

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

Posted: 27 Apr 2024, 08:18
by boiler
@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.

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

Posted: 27 Apr 2024, 09:28
by alawsareps
@boiler
You're right, my apologies.