How do I specify C:\Program Files without a space in it for programs that can't handle spaces in file paths?

前端 未结 14 1326
星月不相逢
星月不相逢 2020-12-01 04:39

A configuration file needs position of another file,

but that file is located in \"C:\\Program Files\",

and the path with space in it is not recognized,

相关标签:
14条回答
  • 2020-12-01 05:28

    Use the following notations:

    • For "C:\Program Files", use "C:\PROGRA~1"
    • For "C:\Program Files (x86)", use "C:\PROGRA~2"

    Thanks @lit for your ideal answer in below comment:

    Use the environment variables %ProgramFiles% and %ProgramFiles(x86)%

    :

    0 讨论(0)
  • 2020-12-01 05:33

    Either use the generated short name (C:\Progra~1) or surround the path with quotation marks.

    0 讨论(0)
  • 2020-12-01 05:35

    Never hardcode this location. Use the environment variables %ProgramFiles% or %ProgramFiles(x86)%.

    When specifying these, always quote because Microsoft may have put spaces or other special characters in them.

    "%ProgramFiles%\theapp\app.exe"
    "%ProgramFiles(x86)%\theapp\app.exe"
    

    In addition, the directory might be expressed in a language you do not know. http://www.samlogic.net/articles/program-files-folder-different-languages.htm

    >set|findstr /i /r ".*program.*="
    CommonProgramFiles=C:\Program Files\Common Files
    CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
    CommonProgramW6432=C:\Program Files\Common Files
    ProgramData=C:\ProgramData
    ProgramFiles=C:\Program Files
    ProgramFiles(x86)=C:\Program Files (x86)
    ProgramW6432=C:\Program Files
    

    Use these commands to find the values on a machine. DO NOT hardcode them into a program or .bat or .cmd file script. Use the variable.

    set | findstr /R "^Program"
    set | findstr /R "^Common"
    
    0 讨论(0)
  • 2020-12-01 05:35

    You can just create a folder ProgramFiles at local D or local C to install those apps that can be install to a folder name which has a SPACES / Characters on it.

    0 讨论(0)
  • 2020-12-01 05:36

    You can use the following methods to specify C:\Program Files without a space in it for programs that can't handle spaces in file paths:

    'Path to Continuum Reports Subdirectory - Note use DOS equivalent (no spaces)
    RepPath = "c:\progra~1\continuum_reports\" or
    RepPath = C:\Program Files\Continuum_Reports  'si es para 64 bits.
    
    ' Path to Continuum Reports Subdirectory - Note use DOS equivalent (no spaces)
    RepPath = "c:\progra~2\continuum_reports\" 'or
    RepPath = C:\Program Files (x86)\Continuum_Reports  'si es para 32 bits.
    
    0 讨论(0)
  • 2020-12-01 05:38

    The Windows shell (assuming you're using CMD.exe) uses %ProgramFiles% to point to the Program Files folder, no matter where it is. Since the default Windows file opener accounts for environment variables like this, if the program was well-written, it should support this.

    Also, it could be worth using relative addresses. If the program you're using is installed correctly, it should already be in the Program Files folder, so you could just refer to the configuration file as .\config_file.txt if its in the same directory as the program, or ..\other_program\config_file.txt if its in a directory different than the other program. This would apply not only on Windows but on almost every modern operating system, and will work properly if you have the "Start In" box properly set, or you run it directly from its folder.

    0 讨论(0)
提交回复
热议问题