Move files older than X days in a subfolder structure

Kurratot 1 Reputation point
2022-02-07T11:57:42.217+00:00

I have a folder structure like this

Firm1
Firm2
Firm3
.....
Firm 256

In each folder there are two subfolders:
Serverlogging
ReportResults

What I want to do is to find all files ( .) for each firm older than X days.

These files should be moved to
//archive/Firm1/Serverlogging
//archive/Firm1/ReportResults
//archive/Firm2/Serverlogging
//archive/Firm2/ReportResults

..and so on.

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,293 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ravi Kanth Koppala 3,231 Reputation points Microsoft Employee
    2022-02-07T17:32:48.333+00:00

    @Kurratot ,
    Thank you for reaching out to the Microsoft Q&A platform. Happy to answer your question.

    We can do such automation using PowerShell and here is the script which moves all files from the current folder to another folder that are created 7 days back.

    $files = Get-ChildItem -File | Where-Object {$_.CreationTime -gt (Get-Date).AddDays(-7)}  
    foreach ($f in $files){  
    Move-Item -Path $f -Destination .\Temp\$f   
    }  
    

    Please "Accept as Answer" and Upvote if any of the above helped so that, it can help others in the community looking for remediation for similar issues.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.