1. Perl
  2. File operations
  3. here

Absolute path and relative path

In the program, there are two ways to express the file name: absolute path and relative path. The absolute path is the file name described without omitting the file name from the root. A relative path is a file name written relative to the current directory.

Examples of absolute and relative paths

Twice For Unix-like OS For Windows
Absolute path example

/home/yk/example1

c:\home\yk\example1.txt
Relative path example (* 1) example1 example1.txt

* 1 When the current directories are "/ home/yk" and "c:\home\yk" respectively

How to interpret absolute paths and relative paths.

If the file name starts with /, it is interpreted as an absolute path, and if it does not start with /, it is interpreted as a relative path. Similar for Windows, if it starts with c:\(drivename \) it is interpreted as an absolute path, otherwise it is interpreted as a relative path.

What is the current directory?

The current directory is the directory that is the base point for relative path names. When executing from a command prompt or shell, the directory where the script is executed becomes the current directory.

File name and directory name cannot be distinguished from the name.

/ home/yk/example1 can be a directory or a file. If you say/home/yk/example1 /, it will always be the directory name. (For Windows, c:\home\yk\example1 \)

Related Informatrion