Filepaths Explained Simply | No Code Explanation

Madhav Malhotra
Madhav Malhotra
126 بار بازدید - پارسال - I see too many programming
I see too many programming tutorials assume you know how filepaths work or explain them while also throwing complicated code at you. So I recorded this no code explanation of what filepaths are, why they're useful, and how they work.

_____________________________________________________
Written Summary
_____________________________________________________
Filepaths = urls, but on your computer. The way you tell the computer where to find a file.

   You need them as an alternative to the 'Files' app that you use on your computer, where you can click on files and folders instead of writing down a path to them.

Parts of a Filepath:

   Filepaths have two parts: folders (directories) and files.

   Ex: Let's say you wanted to tell a computer to do something with a file called image.png in the current folder you have open. You could just tell Python the name of the file "image.png" and it'll assume you want to look for it in the current folder.
   Ex: Let's say you have your computer's Downloads folder open. You create another folder inside it called test . And you put an image called image.png inside this test folder. Then, you could specify the filepath to that image as "test/image.png". Note how a slash separates folders and files.

   You could continue 'nesting' folders as much as you wanted. Ex: "saved/homework/math/assignment.pdf" refers to the assignment.pdf file in the math folder in the homework folder in the saved folder (which is located in the current Downloads folder you have open).

Special Symbols:

   If you ever want a short way to write the current folder you have open, you write ./ . Ex: ./image.png is the same as image.png (it tells the computer to look for that file in the current folder). Ex: ./saved/homework/math/assignment.pdf is the same thing as saved/homework/math/assignment.pdf
   This is in contrast to the 'parent folder' (the folder that contains the folder you currently have open). To refer to this, you use ../

   Ex: Let's say you had open the math folder located at Downloads/saved/homework/math . Then ../ would refer to the parent of the math folder (which is the homework folder). And ../../ would refer to the parent of the parent of the math folder (which is the saved folder).
   Ex: If you had the math homework folder open, but wanted to tell the computer to open a science assignment file, you might use ../../assignments/science/a1.pdf (which ends up being saved/assignments/science/a1.pdf based on what I said above on what ../../ becomes.

   Also, you have this thing called the 'root folder'. Think of this as the default folder that your computer opens when it first starts. It's represented by the / symbol alone.

   Ex: /Users/yourName/Downloads/would be a path from the root folder to your downloads folder.
   Ex: /Users/yourName/Downloads/saved/homework/math/assignment.pdfwould be a path from the  root folder to the assignments file.
   The advantage of specifying this path instead of opening (for instance) the math folder and then specifying just assignment.pdf is that the path based on the root folder will work no matter which folder you have open at the moment. Whereas the shorter path will only work if you have the  math folder open.
   Because filepaths with the root symbol work absolutely all the time, we call them absolute fllepaths. Every other filepath I gave as an example above is called a relative filepath. Because it only can find files relative to the current folder you have open.  


P.S. Yes, I know I wasn't in the actual Linux root directory... hush.
پارسال در تاریخ 1401/12/11 منتشر شده است.
126 بـار بازدید شده
... بیشتر