{"id":614,"date":"2020-01-02T18:24:29","date_gmt":"2020-01-02T23:24:29","guid":{"rendered":"http:\/\/newmediaproduction.mynmi.net\/?page_id=614"},"modified":"2022-02-01T20:43:40","modified_gmt":"2022-02-01T20:43:40","slug":"files-folders","status":"publish","type":"page","link":"https:\/\/nmi.cool\/web\/files-folders\/","title":{"rendered":"Files and Folders"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/nmi.cool\/newmediaproduction\/wp-content\/uploads\/sites\/3\/2022\/01\/parking-garage.jpeg\" alt=\"Concrete building foundation with sunlight streaming through pillars\" \/><figcaption>Photo by <a href=\"https:\/\/unsplash.com\/@mirkoblicke\">Mirko Blicke<\/a>.<\/figcaption><\/figure>\n\n\n\n<p>This lesson is of utmost importance<strong> <\/strong>(or as they say in New Girl, <em>upmost <\/em>importance).<strong> <\/strong>It is the building block upon which all other lessons in this course are based, so <strong>read carefully.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concept 1: Webpages are just files<\/h2>\n\n\n\n<p><strong>Although they may look like large impressive documents, webpages are nothing more than files.<\/strong> The result is the webpage that appears in your web browser.<\/p>\n\n\n\n<p>In addition to the text that you read when you view a webpage, the hidden text that actually makes the web page function is known as <strong>source code<\/strong>. Source code tells your web browser (Chrome in our case) how to display the page and where to find pictures, video, and other media files that may make up the webpage. <\/p>\n\n\n\n<p>The pictures and media files are totally separate from the web page itself and are stored in <strong>folders<\/strong>. <\/p>\n\n\n\n<p>This concept can feel a little strange at first but for you to become a competent web developer you must understand and come to terms with it. You may need to come back and reread this lesson a few times when we start working with files. <\/p>\n\n\n\n<p>Right click on the empty space on the side of this website. <strong>Select View Page Source<\/strong>. We\u2019ll learn how to navigate and write some of that code later in this class. <\/p>\n\n\n\n<p>For now, understand that source code is just illustrating the principle that <strong>all webpages are files of text.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concept 2: Folders<\/h2>\n\n\n\n<p>Since each webpage is just a fancy file, and all images and media are also other files, a website can easily consist of hundreds of files: webpages, pictures, videos, products for sale\u2014you get the idea. <\/p>\n\n\n\n<p>The way we organize all these numerous files? <strong>Folders. <\/strong><\/p>\n\n\n\n<p>Here&#8217;s a common folder structure: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"351\" src=\"https:\/\/nmi.cool\/newmediaproduction\/wp-content\/uploads\/sites\/3\/2020\/01\/Basic_Website_Structure-e1578162822503.png\" alt=\"\" class=\"wp-image-710\" srcset=\"https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/Basic_Website_Structure-e1578162822503.png 600w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/Basic_Website_Structure-e1578162822503-300x176.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption>The basic folder structure of a website, consisting of a JavaScript folder, an image folders, and a Cascading Style Sheets folder.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"naming\">Concept 3: Naming files and folder<\/h2>\n\n\n\n<p>We&#8217;ve learned webpages are nothing more than files, and these files are stored in organizational folders. However, these files and folders must be <strong>named <\/strong>in a very specific way. <\/p>\n\n\n\n<p><strong>Capitalization<\/strong> and <strong>spaces<\/strong> matter to web servers and programming languages. A file named <strong>Ana.html<\/strong> is not the same as <strong>ana.html<\/strong>. Likewise, a folder name &#8220;<strong>CSS<\/strong>&#8221; is not the same as a folder named &#8220;<strong>css<\/strong>.&#8221; Notice the casing? While it may be tempting, resist those urges from your English classes to capitalize the first letter. <\/p>\n\n\n\n<p>Additionally, something called Corgi Dog.jpg is not the same as CorgiDog.jpg. <strong>Do not use spaces when naming your files<\/strong>.  <\/p>\n\n\n\n<p>If you\u2019re naming a file two words, and you can\u2019t use a space, how could you make those words easier to tell apart? <\/p>\n\n\n\n<p>Which one is easier to read: <br>A) cordidog.jpg <br>B) corgiDog.jpg <\/p>\n\n\n\n<p>If you guessed B, you\u2019re right! Usually, to name a file multiple words, you capitalize the first letter of the second word, the third word, etc. <\/p>\n\n\n\n<p>Fun fact: this naming convention is called <a href=\"https:\/\/techterms.com\/definition\/camelcase\">camelCase<\/a>. <\/p>\n\n\n\n<p>In some cases, you might want to add a hyphen or underscore between words. That&#8217;s acceptable as well. <\/p>\n\n\n\n<p><strong>Pro Tip:<\/strong> If you&#8217;re working on a project and you&#8217;ve uploaded your files to your server, but they aren&#8217;t showing up, it&#8217;s a great idea to double check that your files and folders are named using the best practices outlined above. Consistency is key here: the file and folder names must <strong>appear exactly the same<\/strong> in Dropbox, in your HTML, and on your server. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"filepaths\">Concept 4: File paths<\/h2>\n\n\n\n<p>To link files together, to display images, to have files communicating with each other, you have to use <strong>file paths<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>To make files talk to one another, you have to provide a file path between them \u2014 basically a route, so one file knows where another one is.<\/p><cite><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/Getting_started_with_the_web\/Dealing_with_files\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Dealing with files (opens in a new tab)\">Dealing with files<\/a>, via <a href=\"https:\/\/developer.mozilla.org\/en-US\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"MDN web docs (opens in a new tab)\">MDN web docs<\/a><\/cite><\/blockquote>\n\n\n\n<p>While you may be used to <strong>searching <\/strong>for files, this is essentially the opposite. We have to provide the server with <strong>exact instructions <\/strong>on where to find the file.<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p>For this example, imagine we are our editing a file, <strong>index.html<\/strong>, and we want to insert a picture of a Dalmatian.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;!DOCTYPE html&gt; <\/code>\n<code>&lt;head&gt;        <\/code>\n<code>&lt;title&gt;Learning About File Paths&lt;\/title&gt;   <\/code>\n<code>&lt;\/head&gt;   <\/code>\n  <code>&lt;body&gt;     <\/code>\n    <code><strong>&lt;img src=\"\" alt=\"<\/strong><\/code><strong>dalmatian<\/strong><code><strong>\"&gt;  <\/strong> <\/code>\n  <code>&lt;\/body&gt; <\/code>\n<code>&lt;\/html&gt; <\/code><\/pre>\n\n\n\n<p>The line  <code><strong>&lt;img src=\"\" alt=\"dalmatian\"&gt;<\/strong><\/code> is inserting an image  (img) into a page. Between the quotes, we need to provide instructions on <strong>exactly<\/strong> where the image is located. In this case, dalmatian.jpg is in the images folder\u2014see image below. Therefore, we specify the <strong>folder name<\/strong> followed<strong> <\/strong>by the file name:<strong> images\/dalmatian.jpg<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1638\" height=\"350\" src=\"https:\/\/nmi.cool\/newmediaproduction\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-dalmation.png\" alt=\"Folder structure highlighting the file path to dalmatian.jpg\" class=\"wp-image-1028\" srcset=\"https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-dalmation.png 1638w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-dalmation-300x64.png 300w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-dalmation-1024x219.png 1024w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-dalmation-768x164.png 768w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-dalmation-1536x328.png 1536w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-dalmation-1568x335.png 1568w\" sizes=\"auto, (max-width: 1638px) 100vw, 1638px\" \/><figcaption>Folder structure highlighting the file path to dalmatian.jpg. You&#8217;ll be downloading this file structure for the course (minus dalmatian.jpg) in an upcoming lesson.<\/figcaption><\/figure>\n\n\n\n<p>The file path <strong>images\/dalmatian.jpg<\/strong> is instructing the server to go <strong>down <\/strong>into the <strong>images folder<\/strong> and find the file titled dalmatian.jpg. <\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1234\" height=\"332\" src=\"https:\/\/nmi.cool\/newmediaproduction\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-pages-on-same-level.png\" alt=\"Folder structure highlighting the file path to about.html\" class=\"wp-image-1029\" srcset=\"https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-pages-on-same-level.png 1234w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-pages-on-same-level-300x81.png 300w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-pages-on-same-level-1024x276.png 1024w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-pages-on-same-level-768x207.png 768w\" sizes=\"auto, (max-width: 1234px) 100vw, 1234px\" \/><\/figure>\n\n\n\n<p>If we wanted to link two files in the same folder level, for instance, add a link <strong>about.html on index.html<\/strong>, we don&#8217;t need to include a folder name. They&#8217;re already in the same folder. <\/p>\n\n\n\n<p>The file path would simply say the file name: <strong>about.html<\/strong> <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;!DOCTYPE html&gt; <\/code>\n<code>&lt;head&gt;        <\/code>\n<code>&lt;title&gt;Learning About File Paths&lt;\/title&gt;   <\/code>\n<code>&lt;\/head&gt;   <\/code>\n  <code>&lt;body&gt;     <\/code>\n    <code><strong>&lt;a href=\"about.html\"&gt;About&lt;\/a&gt;  <\/strong> <\/code>\n  <code>&lt;\/body&gt; <\/code>\n<code>&lt;\/html&gt; <\/code><\/pre>\n\n\n\n<p>Again, don&#8217;t worry if the code around the file path is a little confusing\u2014for now, just focus on the relationships between files.<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p>Things get a little tricker when you need to go <strong>UP <\/strong>a folder level.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"894\" height=\"390\" src=\"https:\/\/nmi.cool\/newmediaproduction\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-different-view.png\" alt=\"File and folder structure highlighting going up a level.\" class=\"wp-image-1030\" srcset=\"https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-different-view.png 894w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-different-view-300x131.png 300w, https:\/\/nmi.cool\/web\/wp-content\/uploads\/sites\/3\/2020\/01\/file-paths-different-view-768x335.png 768w\" sizes=\"auto, (max-width: 894px) 100vw, 894px\" \/><figcaption>Folder structure\u2014view switched only so you can see in multiple folders at once.<\/figcaption><\/figure>\n\n\n\n<p>If we are working on <strong>project-one.html<\/strong>, located in the project-one folder, and we wanted to insert an image called <strong>dalmatian.jpg<\/strong>, we would need to:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Go <strong>UP<\/strong> a folder. This is depicted by: <strong>..\/<\/strong><\/li><li>Go <strong>DOWN <\/strong>into the images folder:<strong> \/images<\/strong><\/li><li>Add the file name: <strong>dalmatian.jpg<\/strong><\/li><li>The final file path: <strong>..\/images\/dalmatian.jpg<\/strong><\/li><\/ol>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p class=\"has-text-align-left has-light-gray-background-color has-background\"><strong>To reinforce these concepts, read: <\/strong><br><a rel=\"noreferrer noopener\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/Getting_started_with_the_web\/Dealing_with_files\" target=\"_blank\">Dealing with files<\/a>, via MDN web docs<br><a rel=\"noreferrer noopener\" aria-label=\"HTML file paths (opens in a new tab)\" href=\"https:\/\/www.w3schools.com\/html\/html_filepaths.asp\" target=\"_blank\">HTML file paths<\/a>, via W3Schools<br><br>And ask for help if you need it.<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p><strong>Your turn<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>What is the file path to insert <strong>dalmatian.jpg<\/strong> on <strong>project-one.html<\/strong>?<\/li><li>What is the file path to link <strong>project-one.html <\/strong>on <strong>index.html<\/strong>?<\/li><li>If you wanted to link <strong>index.html <\/strong>on your <strong>project-one.html<\/strong>, what would that file path look like?<\/li><li>How would you name a webpage about Baby Yoda, paying close attention to <strong>casing<\/strong> and <strong>spacing<\/strong>?<\/li><li>How would you name an image of <strong>Yoda<\/strong>?<\/li><\/ol>\n\n\n\n<p><em>For answers, navigate to page 2.<\/em><\/p>\n\n\n\n<!--nextpage-->\n\n\n\n<hr class=\"wp-block-separator has-text-color has-background has-white-background-color has-white-color\" \/>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Answers<\/strong>:\n1. ..\/images\/dalmatian.jpg\n2. project-one\/project-one.html\n3. ..\/index.html\n4. babyYoda.html\n5. yoda.jpg\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This lesson is of utmost importance (or as they say in New Girl, upmost importance). It is the building block upon which all other lessons in this course are based, so read carefully. Concept 1: Webpages are just files Although they may look like large impressive documents, webpages are nothing more than files. The result &hellip; <a href=\"https:\/\/nmi.cool\/web\/files-folders\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Files and Folders<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-614","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/pages\/614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/comments?post=614"}],"version-history":[{"count":3,"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/pages\/614\/revisions"}],"predecessor-version":[{"id":3765,"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/pages\/614\/revisions\/3765"}],"wp:attachment":[{"href":"https:\/\/nmi.cool\/web\/wp-json\/wp\/v2\/media?parent=614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}