0

I am trying to figure these out, but every single thing I read says exactly what I've already read in a previous article. I understand it theoretically, but I have no idea what how to write it into a code. I am such a noob and I need lots of help!

Paul Roub
  • 36,322
  • 27
  • 84
  • 93

1 Answers1

0

A relative path is the location of the file/folder relative to where you are. The absolute path is the full location. For example:

"C:\Product\Folder\SubFolder\file.exe" might be the absolute path of a file on your machine. But if you're already in C:\Product the relative path to that file would just be "Folder\SubFolder\file.exe". It's like knowing someone's full mailing address or knowing how to get to their house from yours. You may not need to know where you are in the world to know how to get from one place to another (your house to a coffee shop for example).

In code, you would use the absolute path if you're explicitly looking for a file at this location. But you may not always know the absolute location where your app is executing, and you are trying to access files that you control. In this case you only need to know how to get there based on where you are.

For example, My app may be installed at the following absolute paths "C:\Company\Product\app.exe" and my have had a library of files installed under that in the folder "C:\Company\Product\Files\". The absolute path may change if the user decides to install it in another location. But you still control the "Files" folder, so you would code the relative path of "Files\file.txt" to access it.

If you're still struggling with the difference. Think of the absolute path like the postal address of a chain store. Where every instance of that store is identical. The absolute path is the location of an item in a specific instance of that store (location of the store + location of item within the store). The relative path is just the location in the store. If the store were your app, or you were in a store, you don't really care where you are (which instance of the store you're in). You just need to know where the item is in the store. Relative path is knowing an item is in Row 2, second shelf from the bottom, third from the right. To you, it doesn't matter which store your in, you can still find it.

mminneman
  • 426
  • 3
  • 7
  • How do i find out where I am then? Thank you. – isitdawnordown Nov 25 '19 at 21:05
  • If you're trying to find the location of your app, in C# you would use something like Assembly.GetExecutingAssembly(), then its path. https://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in – mminneman Nov 25 '19 at 21:11
  • I am sorry I am such a noob. What is C#? – isitdawnordown Nov 25 '19 at 21:13
  • It's a programming language, since you're on this site, I tried to answer in programming terms. Outside of programming an absolute path is where a file is, you can covert an absolute path to a relative path by cutting off the part that not necessary. Like a file in my itunes library might be "C:\users\user\itunes\media\band\album\song.mp4" but if I copied everything in "C:\users\user\itunes\media" to a backup location. The relative paths would start there, so just be "band\album\song.mp4". You do this alot converting playlists from absolute to relative putting them on an SD card or something. – mminneman Nov 25 '19 at 21:20