Paths

Absolute vs Relative Paths

Absolute path makes no assumptions about your current location in relation to the location of the file or directory it's describing.

Relative path is location relative to your current location.

# absolute /root/project/parent/file.txt # relative ../parent/file.txt

Special Characters in Paths

# ~ ## ~ is a Linux shortcut for user's home directory ~/Desktop # path to desktop # / / # root directory of filesystem ./ # current directory ./file_name # run file_name in shell # pwd /Volumes/STORAGE/Folder_Name/Current_Folder # __dirname ## Absolute path to directory conataining the currently executing file/script is located in. /d1/d2/myscript.js # /d1/d2 # . #

__dirname

__dirname returns absolute path of the directory containing the currently executing file.

Points to where the code/file is stored in the repository file structure.

vs process.cwd()

process.cwd() returns the value of directory where we run the process.

It will return the current directory of the terminal calling the script.

Wildcards

Allows you to collect all files of a certain type within one or more directories.

Asterisk (*)

  • subtitutes for any zero or more characters
  • when used in path

question mark

? # substitute for any one character

Current Working Directory (cwd)

Every process has a current directory

  • When a process starts, it simply inherits the current directory from its parent process.
  • When a process starts, current directory is not set to the directory which contains the program you are running.

pwd

pwd stands for print working directory.

  • Same thing as cwd, just a command to print out the location.

History

When disks became large enough that you did not want all your files in the same place, operating system vendors came up with a way to structure files in directories.

Directory is just a peculiar type of file, whose contents is a collection of other files, which can also include other directories.

Directories introduced the concept of a current working directory.

  • What if you could say "from now on, until I say otherwise, all the files I am talking about will be in this particular directory"
  • Thus was the cd command born