search

Home  >  Q&A  >  body text

c++ - windows里的短路径是个什么写法?

大家讲道理大家讲道理2767 days ago606

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:31:09

    This is not a short path, it is an environment variable.
    Using variables is of course more general. Hard-coded things can only work on your own machine.

    Take the python you mentioned as a small example. You wrote a clear.py script file, whose function is to clean up the user's system temporary folder.
    If you don’t use variables, you might write it like this (pseudocode)

    del C:\Users\adminstrator\AppData\Local\Temp\*.*

    A script like yours cannot be run on other people’s machines. First of all, you need to know the currently logged-in user name, and you have to call the API to know the user’s Temp folder path (maybe on the D drive or E drive) Possibly)

    But if you use the system’s default %TEMP% variable, you don’t need to worry about it

    del %TEMP%\*.*

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:31:09

    To enhance program portability. For example, whether your Windows is installed on the C drive, D drive, or some X drive, the program can be accessed through a short path without the need to hard code the specific path.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:31:09

    The actual installation directories of different computers are not necessarily the same. For example, some of the same software is installed on the c drive and some on the d drive. The actual location is saved through such an environment variable. The program only needs to access the environment variable. , which can enhance the portability of the program.

    reply
    0
  • Cancelreply