{"id":4454,"date":"2023-05-13T23:13:00","date_gmt":"2023-05-14T06:13:00","guid":{"rendered":"https:\/\/blog.colterhicks.com\/?p=4454"},"modified":"2025-09-30T01:39:38","modified_gmt":"2025-09-30T08:39:38","slug":"how-to-make-multiple-folders-from-text-file","status":"publish","type":"post","link":"https:\/\/blog.dabbleden.com\/index.php\/2023\/05\/13\/how-to-make-multiple-folders-from-text-file\/","title":{"rendered":"How To: Make Multiple Folders From Text File"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1014\" height=\"367\" src=\"http:\/\/blog.dabbleden.com\/wp-content\/uploads\/2024\/01\/image-1.png\" alt=\"\" class=\"wp-image-4456\" srcset=\"https:\/\/blog.dabbleden.com\/wp-content\/uploads\/2024\/01\/image-1.png 1014w, https:\/\/blog.dabbleden.com\/wp-content\/uploads\/2024\/01\/image-1-300x109.png 300w, https:\/\/blog.dabbleden.com\/wp-content\/uploads\/2024\/01\/image-1-768x278.png 768w\" sizes=\"auto, (max-width: 1014px) 100vw, 1014px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">The Code<\/h2>\n\n\n\n<p>On Windows, if you open up PowerShell ISE, you can paste this into a new script file.<\/p>\n\n\n\n<p>It will run from the folder it is placed in so make sure you have a blank folder to start.<\/p>\n\n\n\n<p><strong>Create a new text file in the same directory called &#8220;People.txt&#8221;<\/strong>. If you have another use case then rename this to whatever is appropriate but make sure you rename the file name in the script below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it&#8217;s used<\/h2>\n\n\n\n<p>This references the &#8220;People.txt&#8221; file and makes a folder for every line entered into the file. It then copies that file into a secondary file to reference from for future runs.<\/p>\n\n\n\n<p>When run a second time, it compares the &#8220;OldNames.txt&#8221; it created to the &#8220;People.txt&#8221; that may be updated with additional names, and archives names that are no longer applicable if they were removed from the &#8220;People&#8221; list. Additional people added will have a new folder created.<\/p>\n\n\n\n<p>This is for roles that manage a lot of assets, or needs to keep records for individuals in your organization, or if you just need to make a folder managing tool from a text file for any home use.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Sets the path this script is running from\n$Path = $PSScriptRoot\n\n#Gathers the names from the \"Old\" file\n$OldNames = Get-Content -Path $Path\\OldNames.txt\n\n#Gathers the names from the \"People\" File.\n$People = Get-Content -Path $Path\\People.txt\n\n\n# Archive the folders of people that have left\nForEach ($oldPerson in $OldNames) {\n  if ($oldPerson -notin $People) {\n    Move-Item -Path $Path\\$oldPerson -Destination \"$Path\\1. Archive\"  -Force\n  }\n} \n\n\n# Make Folders for new people\nForEach ($Person in $People) {\n    # Create a new folder for each line.\n    New-Item -ItemType Directory -Path $Path -Name $Person -Force\n}\n\n#Archive OldNames and Rename People. Make new blank People file\nMove-Item -Path $Path\\OldNames.txt -Destination \"$Path\\1. Archive\\1. OldNames\" -Force\nCopy-Item -Path $Path\\People.txt -Destination \"$Path\\OldNames.txt\" -Force\n#New-Item -ItemType File -Name People.txt -Force<\/code><\/pre>\n\n\n\n<p>I&#8217;m not an expert in code, or PowerShell, but if you have any ways this could be run better please let me know! I needed it for myself but figured I would share it if it&#8217;s useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Code On Windows, if you open up PowerShell ISE, you can paste this into a new script file. It will run from the folder it is placed in so make sure you have a blank folder to start. Create a new text file in the same directory called &#8220;People.txt&#8221;. If you have another use [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":4460,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,12],"tags":[],"class_list":["post-4454","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it","category-productivity"],"jetpack_featured_media_url":"https:\/\/blog.dabbleden.com\/wp-content\/uploads\/2024\/01\/image-1-3.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/posts\/4454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/comments?post=4454"}],"version-history":[{"count":3,"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/posts\/4454\/revisions"}],"predecessor-version":[{"id":4771,"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/posts\/4454\/revisions\/4771"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/media\/4460"}],"wp:attachment":[{"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/media?parent=4454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/categories?post=4454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.dabbleden.com\/index.php\/wp-json\/wp\/v2\/tags?post=4454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}