Explaining Filepaths and "cd ." for Beginners
Tags: webdev, beginners, programming, tutorial
Published: 2023-04-18 17:21:09

## Explaining Filepaths and "cd ." for Beginners

### What is a filepath?

A filepath is like a set of directions that helps a computer find a file or folder. Think of it like giving a friend directions to a store in a big city.

Computers use forward slashes (`/`) or backslashes (`\`) to show the path to a file or folder. In many computer systems, a filepath could look like this:

`/home/user/Documents/example.txt`.

This filepath leads to a file called `example.txt` inside the `Documents` folder, which is inside the `user` folder, which is inside the `home` folder.

In Windows, filepaths use backslashes, like this:

`C:\Users\User\Documents\example.txt`.

### Finding your current filepath

You can find your current filepath by opening a command prompt on your computer.

On Windows, you can open a command prompt by pressing the Windows key and typing `cmd`.

On Mac, you can open a command prompt by pressing the Command key and the spacebar at the same time, typing `terminal`, and pressing Enter.

Once you have a command prompt open, you can type the command `pwd` to find your current filepath. The command `pwd` stands for "print working directory." It tells you where you are in the file system.

Knowing your current filepath can be helpful when you need to find a file or folder or when you need to navigate to a particular directory using the command prompt.

### What is "cd ."?

The command `cd` stands for "change directory." It's used to move around in the file system. For example, if you're in the `home` folder and you want to move to the `user` folder, you can use the command `cd user`.

The command `cd .` helps you stay in the same folder when using a command prompt on a computer. The `.` represents "the current folder." So it tells the computer, "stay in the folder we're in right now."

If you want to go up one level, you can use the command `cd ..`. The `..` means "start where we are now, but go up one level." So it tells the computer, "go up one level from the folder we're in right now."

### When we will see the `.` and `..` in our code

When making a website, we use filepaths to show the web browser where to find different files, like images, stylesheets, and scripts.

For instance, we might use `./scripts/main.js` to include a JavaScript file in a website or `./styles/main.css` to link to a CSS stylesheet file.

```html
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="./styles/main.css">
  </head>
  <body>
    <script src="./scripts/main.js"></script>
  </body>
</html>
```

Remember from above that the `.` at the start of these filepaths means "start in the current folder." So it tells the browser, "look in the folder we're in right now to find the file."

It's essential to write filepaths correctly, using the right slashes and correct spelling. Computers are very picky about these details!

Knowing how to work with filepaths and navigate the file system using commands like `cd .` and `cd ..` can make your work on the computer much more efficient and productive.

Thank you for reading this introduction to filepaths and the `cd .` command. I hope it has helped you better understand how to navigate and access files on your computer. 

If you have any questions or comments, please feel free to leave them below. And if you're interested in learning more about technology and programming, you can connect with me on LinkedIn at [https://www.linkedin.com/in/olitreadwell](https://www.linkedin.com/in/olitreadwell).

What has been your biggest challenge when it comes to working with filepaths on your computer?