# New help with a powershell situation

**URL:** <https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212>\
**Category:** PowerShell Help\
**Created:** [August 27, 2018, 3:23pm UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212 "2018-08-27T15:23:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fortdru](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@fortdru](https://forums.powershell.org/u/fortdru)\
**Post date:** [August 27, 2018, 3:23pm UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212/1 "2018-08-27T15:23:26Z")

</div>

Basically moving/sorting multiple files and creating folders corresponding to that file. for example 20180102.txt file has to be moved to corresponding folder 2018\01\02  
We need a Powershell script that

1. reads thru the current directory (where the script resides)
2. identifies the correct date that the file represents
3. Checks the existing folder structure, if it exists CURRENT FOLDER\year\xx monthname\xx(day).  
Example for file 59\_20180102.txt it should go to folder \2018\01 January\02\
4. Creates the folder structure, as needed, for the files CURRENT FOLDER\year\xx monthname\xx(day)
5. it should only create folders as needed, meaning for existing files. If I have only one file, it should only create that day folder
6. moves each txt file to the appropriate folder  
What is the simplest/ most efficient cmdlet/script to do this. Greatly appreciated.

&nbsp;

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 27, 2018, 4:15pm UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212/2 "2018-08-27T16:15:07Z")

</div>

I doupt that there will be a ready to use script for exactly that requirement you have. You will probably have to create one by yourself. You could start with [Get-ChildItem](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-5.1), [Where-Object](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/where-object?view=powershell-5.1), [Foreach-Object](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-5.1), [New-Item](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-5.1), [Move-Item](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/move-item?view=powershell-5.1) and some [conditions/comparisons](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-5.1).

---

<div class="post-metadata">

**Author:** ![fortdru](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@fortdru](https://forums.powershell.org/u/fortdru)\
**Post date:** [August 28, 2018, 5:13am UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212/3 "2018-08-28T05:13:51Z")

</div>

@olaf I do see those cmdlets. But can those move multiple files at once? To make it more efficient? There are about rough 120 files, and I have to move each of them into a separate corresponding file. So that could take some time.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 28, 2018, 5:39am UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212/4 "2018-08-28T05:39:44Z")

</div>

> ... But can those move multiple files at once? ...

If you mean parallel - with a normal script - NO, not by default. They are usually copied sequencially. But it would be a script. You don't have to copy them one by one. That does the script for you.

> ... To make it more efficient?

It doesn't have to be more efficient just because it's parallel. You could use jobs if you need to do it parallel anyway.

> ... So that could take some time. ...

So what? It would be a script. It runs without interaction. You don't have to watch it running!! ;-)

Why don’t you just start trying it? It will not hurt you.

---

<div class="post-metadata">

**Author:** ![fortdru](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@fortdru](https://forums.powershell.org/u/fortdru)\
**Post date:** [August 28, 2018, 5:49am UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212/5 "2018-08-28T05:49:44Z")

</div>

@olaf, ok I will try something, then post what I get. Thank you for your assistance.

---

<div class="post-metadata">

**Author:** ![fortdru](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@fortdru](https://forums.powershell.org/u/fortdru)\
**Post date:** [August 28, 2018, 7:25am UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212/6 "2018-08-28T07:25:23Z")

</div>

PS C:\test\goto\> new-item -ItemType directory -name[03] -path C:\test\goto\2018 | ForEach-Object -InformationVariable[59\_201803xx.txt]

cmdlet ForEach-Object at command pipeline position 2

Supply values for the following parameters:

Process[0]: get-childitem -path C:\test\goto

Process[1]: -membername 59\_20180301.txt

Process[2]:

PS C:\test\goto\>

&nbsp;

And these are the examples of the files

-a---- 5/3/2018 5:15 PM 0 59\_20180103.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180104.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180105.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180106.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180107.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180108.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180109.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180110.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180111.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180112.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180113.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180114.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180115.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180116.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180117.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180118.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180119.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180120.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180121.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180122.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180123.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180124.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180125.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180126.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180127.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180128.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180129.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180130.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180131.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180201.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180202.txt

-a---- 5/3/2018 5:15 PM 0 59\_20180203.txt

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/new-help-with-a-powershell-situation/11212/7 "2024-05-16T20:34:29Z")

</div>


