Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Move folders with dates to other dated folders

$
0
0

I have a series of folders like this:

2016-01 2016-02 2016-03 2015-01 2015-02 2015-03 

I’d like to move them to folders for the year in the same folder and create those folders if they don’t exist:

2016 2015 

So really I’m looking for any folder matching the pattern:

20([0-9]{2})-[0-9]{2} 

and moving it to a folder corresponding to:

20$1 

and creating that folder if it doesn’t exist.

How can I do this in PowerShell?

I’ve tried a simple case for a single folder like this, but it doesn’t work:

$dir1 = "C:inetpublogslogfilesW3SVC51" Get-ChildItem -Path $dir1 | Where-Object {$_.PSIsContainer -eq $True} | Select-String -Pattern "2012" |Move-Item -Destination $dir1+"2012" 

submitted by /u/JeffIpsaLoquitor
[link] [comments]

The post Move folders with dates to other dated folders appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles