{"id":17676578,"url":"https://github.com/trossr32/ps-flatten-folders","last_synced_at":"2025-05-12T21:26:24.415Z","repository":{"id":44378984,"uuid":"273571587","full_name":"trossr32/ps-flatten-folders","owner":"trossr32","description":"A Powershell module that moves files from all sub-directories to the parent directory","archived":false,"fork":false,"pushed_at":"2024-01-14T17:26:59.000Z","size":91,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T15:22:01.856Z","etag":null,"topics":["cmdlet","directories","net8","powershell","powershell-module","powershell-modules"],"latest_commit_sha":null,"homepage":"https://powershellgallery.com/packages/FlattenFolders","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trossr32.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-19T19:29:31.000Z","updated_at":"2024-06-22T21:14:47.000Z","dependencies_parsed_at":"2024-01-14T18:55:41.001Z","dependency_job_id":"935f7985-d7b7-4743-a20f-cd6339181065","html_url":"https://github.com/trossr32/ps-flatten-folders","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fps-flatten-folders","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fps-flatten-folders/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fps-flatten-folders/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trossr32%2Fps-flatten-folders/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trossr32","download_url":"https://codeload.github.com/trossr32/ps-flatten-folders/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243208702,"owners_count":20254086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmdlet","directories","net8","powershell","powershell-module","powershell-modules"],"created_at":"2024-10-24T07:26:06.548Z","updated_at":"2025-03-12T11:30:37.401Z","avatar_url":"https://github.com/trossr32.png","language":"C#","funding_links":["https://ko-fi.com/K3K22CEIT'"],"categories":[],"sub_categories":[],"readme":"# FlattenFolders\n\n[![PowerShell Gallery Version](https://img.shields.io/powershellgallery/v/FlattenFolders?label=FlattenFolders\u0026logo=powershell\u0026style=plastic)](https://www.powershellgallery.com/packages/FlattenFolders)\n[![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/FlattenFolders?style=plastic)](https://www.powershellgallery.com/packages/FlattenFolders)\n\nA Powershell module that moves files from all sub-directories to the parent directory.\n\nAvailable in the [Powershell Gallery](https://www.powershellgallery.com/packages/FlattenFolders)\n\n## Description\nMoves files from all sub-directories to the parent directory. If files with duplicate names are found then their file name will have a guid appended to make them unique.\n\nSupports WhatIf. If supplied this will output a formatted table of the from and to file locations that will result from running the cmdlet.\n\nCan be run against: \n\n* a single directory\n* a collection of directories piped into the module.\n\n## Installation (from the Powershell Gallery)\n\n```powershell\nInstall-Module FlattenFolders\nImport-Module FlattenFolders\n```\n\n## Parameters\n\n#### -Directory (alias -D)\n*Optional*. The parent directory where files from all sub-directories will be moved. If neither this nor the Directories parameter are set then the current location will be used.\n\n#### -Directories\n*Optional*. A collection of parent directories where files from all sub-directories will be moved. If neither this nor the Directory parameter are set then the current location will be used.\n\n#### -WhatIf\n*Optional*. If supplied this will output a formatted table of the from and to file locations that will result from running the cmdlet.\n\n#### -DeleteSubDirectories (alias -DS)\n*Optional*. If supplied all sub-directories will be deleted once all files have been moved.\n\n## Example\n\nGiven the following directory structure:\n\n📦flatten me\u003cbr /\u003e\n ┣ 📂parent a\u003cbr /\u003e\n ┃ ┣ 📂sub a\u003cbr /\u003e\n ┃ ┃ ┣ 📜a a New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜a a New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜a a New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📂sub b\u003cbr /\u003e\n ┃ ┃ ┣ 📜a b New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜a b New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜a b New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📂sub c\u003cbr /\u003e\n ┃ ┃ ┣ 📜a c New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜a c New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜a c New Text Document.txt\u003cbr /\u003e\n ┃ ┗ 📂sub d\u003cbr /\u003e\n ┃ ┃ ┣ 📜a c New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜New Text Document.txt\u003cbr /\u003e\n ┣ 📂parent b\u003cbr /\u003e\n ┃ ┣ 📂sub a\u003cbr /\u003e\n ┃ ┃ ┣ 📜New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📂sub b\u003cbr /\u003e\n ┃ ┃ ┣ 📜b New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜b New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜b New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📂sub c\u003cbr /\u003e\n ┃ ┃ ┣ 📜c New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜c New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜c New Text Document.txt\u003cbr /\u003e\n ┃ ┗ 📂sub d\u003cbr /\u003e\n ┃ ┃ ┣ 📜c New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┃ ┣ 📜New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┃ ┗ 📜New Text Document.txt\u003cbr /\u003e\n ┗ 📂parent c\n\nRunning the following command...\n\n```powershell\nPS C:\\\u003e@(\"C:\\temp\\flatten me\\parent a\",\"C:\\temp\\flatten me\\parent b\",\"C:\\temp\\flatten me\\parent c\") | Invoke-FlattenFolders -DeleteSubDirectories\n```\n\n...will move all files from each parent directory's sub-directories into the parent directory and then delete the sub-directories. Files with duplicate names will have a Guid appended to their file names. The result will look like this:\n\n📦flatten me\u003cbr /\u003e\n ┣ 📂parent a\u003cbr /\u003e\n ┃ ┣ 📜a a New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┣ 📜a a New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┣ 📜a a New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📜a b New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┣ 📜a b New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┣ 📜a b New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📜a c New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┣ 📜a c New Text Document - Copy_58888d2c-b089-472b-b166-742701456252.txt\u003cbr /\u003e\n ┃ ┣ 📜a c New Text Document - Copy_59612b2e-d42b-474d-b522-1ffdc4e302fb.txt\u003cbr /\u003e\n ┃ ┣ 📜a c New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📜New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┗ 📜New Text Document.txt\u003cbr /\u003e\n ┣ 📂parent b\u003cbr /\u003e\n ┃ ┣ 📜b New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┣ 📜b New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┣ 📜b New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📜c New Text Document - Copy (2).txt\u003cbr /\u003e\n ┃ ┣ 📜c New Text Document - Copy_1e57ea51-bc54-4f44-a1db-98257b4e839b.txt\u003cbr /\u003e\n ┃ ┣ 📜c New Text Document - Copy_eb5b533c-19b5-4898-9c60-5edc6e6d7ceb.txt\u003cbr /\u003e\n ┃ ┣ 📜c New Text Document.txt\u003cbr /\u003e\n ┃ ┣ 📜New Text Document - Copy (2)_2a39376b-7b8b-4087-bfc4-7c0f25cfc96e.txt\u003cbr /\u003e\n ┃ ┣ 📜New Text Document - Copy (2)_6ab8a5a8-a7b7-4e2b-8eb2-c6e64d7458ea.txt\u003cbr /\u003e\n ┃ ┣ 📜New Text Document - Copy.txt\u003cbr /\u003e\n ┃ ┣ 📜New Text Document_0495b454-56d7-41a6-9f6c-f4ce39a35c3a.txt\u003cbr /\u003e\n ┃ ┗ 📜New Text Document_79c2dd84-b1bf-4660-ba10-3229848b867f.txt\u003cbr /\u003e\n ┗ 📂parent c\n \n ## Further examples\n\nAll files in all sub-directories in the current location (C:\\) will be moved to the current location (C:\\):\n\n```powershell\nPS C:\\\u003e Invoke-FlattenFolders\n```\n\nDisplays an output table to terminal detailing that all files in all sub-directories in C:\\Videos\\ would be moved to C:\\Videos\\:\n\n```powershell\nPS C:\\\u003e Invoke-FlattenFolders -Directory \"C:\\Videos\" -WhatIf\n```\n\nAll files in all sub-directories in C:\\Videos\\ will be moved to C:\\Videos\\ and all sub-directories will be deleted once the files have been moved:\n\n```powershell\nPS C:\\\u003e Invoke-FlattenFolders -Directory \"C:\\Videos\" -DeleteSubDirectories\n```\n\nAll files in all sub-directories in the piped array of directories (C:\\Videos\\ and C:\\Music\\) will be moved to their respective parents:\n\n```powershell\nPS C:\\\u003e \"C:\\Videos\\\",\"C:\\Music\\\" | Invoke-FlattenFolders\n```\n\n## Building the module and importing locally\n\n### Build the .NET core solution\n\n```powershell\ndotnet build [Github clone/download directory]\\ps-flatten-folders\\src\\PsFlattenFoldersCmdlet.sln\n```\n\n### Copy the built files to your Powershell modules directory\n\nRemove any existing installation in this directory, create a new module directory and copy all the built files.\n\n```powershell\nRemove-Item \"C:\\Users\\[User]\\Documents\\PowerShell\\Modules\\FlattenFolders\" -Recurse -Force -ErrorAction SilentlyContinue\nNew-Item -Path 'C:\\Users\\[User]\\Documents\\PowerShell\\Modules\\FlattenFolders' -ItemType Directory\nGet-ChildItem -Path \"[Github clone/download directory]\\ps-flatten-folders\\src\\PsFlattenFoldersCmdlet\\bin\\Debug\\netcoreapp3.1\\\" | Copy-Item -Destination \"C:\\Users\\[User]\\Documents\\PowerShell\\Modules\\FlattenFolders\" -Recurse\n```\n\n### Import the module to your session\n\n```powershell\nImport-Module \"C:\\Users\\[User]\\Documents\\PowerShell\\Modules\\FlattenFolders\\FlattenFolders.dll\"\n```\n\n## Notes\n\nInitially this module was written in native Powershell but has since been upgraded to a .NET 8 Cmdlet. I've archived the Powershell version in case anyone is interested in viewing the differences between the implementations.\n\n- The .NET core version of the module is in the [src](https://github.com/trossr32/ps-flatten-folders/tree/master/src) directory.\n- The Native Powershell version is in the [archived native PS version](https://github.com/trossr32/ps-flatten-folders/tree/master/archived%20native%20PS%20version) directory.\n\n## Contribute\n\nPlease raise an issue if you find a bug or want to request a new feature, or create a pull request to contribute.\n\n\u003ca href='https://ko-fi.com/K3K22CEIT' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi4.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrossr32%2Fps-flatten-folders","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrossr32%2Fps-flatten-folders","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrossr32%2Fps-flatten-folders/lists"}