Summary of Writing Methods of Relative Path and Absolute Path

  • 2021-11-29 08:17:44
  • OfStack

"\" is a special character in C #, and "\" is needed to represent it. Because this writing is inconvenient, C # language provides @ to simplify it.
You can use "\" directly by adding @ to the string. So the path above should be represented in C # as "Book", @ "\ Tmp\ Book", @ "C:\ Tmp\ Book".

Relative paths use the "/" character as the directory separator, while absolute paths can use the "\" or "/" character as the directory separator.

1. Absolute path

Absolute path refers to the path where the file really exists on the hard disk. If you want to use the absolute path to specify the background picture of the web page, you should use the following statement:

<body backround="E:\book\网页布局\代码\第2章\bg.jpg" >

2. Relative paths

The so-called relative path is the location of the target file relative to itself.

In the same directory: < body background="bg.jpg" >

In the "img" subdirectory of its directory: < body background="img/bg.jpg" > (Since the "img" directory is a subdirectory of the "Chapter 2" directory, you don't need to add the "/" character before "img". )

In the parent directory of its directory: < body background="../bg.jpg" > (In relative paths, "../" is often used to denote the upper level 1 directory. If you have more than one level 1 directory, you can use more than one "../".)

In the "img" subdirectory in the parent directory of its directory: < body background="../img/bg.jpg" >

3. Relative virtual directories

<body background="/img/bg.jpg">

Note that there is a "/" character before "img". This "/" represents the root directory of the virtual directory.

Assuming that "E:\ book\ Page Layout\ Code" is set as a virtual directory, the real path of "/img/bg. jpg" is "E:\ book\ Page Layout\ Code\ img\ bg. jpg";


Related articles: