Script to Move Folder Files

%3CLINGO-SUB%20id%3D%22%5C%26quot%3Blingo-sub-3145118%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Bpt-BR%5C%26quot%3B%22%3EScript%20to%20Move%20Folder%20Files%26lt%3B%5C%2Flingo-sub%26gt%3B%3CLINGO-BODY%20id%3D%22%5C%26quot%3Blingo-body-3145118%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Bpt-BR%5C%26quot%3B%22%3E%3CP%3EHi%20people.%20I%20have%20a%20share%20on%20a%20machine%20that%20has%20more%20than%201kk%20files%20and%20the%20manual%20copy%20process%20becomes%20unfeasible.%20I%20know%20the%20command%20to%20move%20these%20files%20to%20another%20folder%2C%20but%20I%20would%20like%20to%20move%20only%20the%20files%20up%20to%2011%2F2021.%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3EAll%20files%20have%20the%20same%20extension.%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3EThanks%2C%20i'm%20sorry.%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%26lt%3B%5C%2Flingo-body%26gt%3B%3CLINGO-LABS%20id%3D%22%5C%26quot%3Blingo-labs-3145118%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Bpt-BR%5C%26quot%3B%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%26lt%3B%5C%2Flingo-label%26gt%3B%26lt%3B%5C%2Flingo-labs%26gt%3B%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3C%2FLINGO-SUB%3E
New Contributor

Hi people. I have a share on a machine that has more than 1kk files and the manual copy process becomes unfeasible. I know the command to move these files to another folder, but I would like to move only the files up to 11/2021.

All files have the same extension.

 

Thanks.

 

4 Replies

@AngeloLobo_79 

 

This searches for all bin files which have been saved before 01/11/2021 as example

Get-ChildItem -path "c:\temp" -Filter *.bin  -Recurse | Where-Object Lastwritetime -lt '01/11/2021'

 

 

Hi @AngeloLobo_79,

 

The PowerShell script you need is as follows. The script is for files with .txt extension before the specified date.

 

$SourceFolder = "C:\OldFolder"
$DestinationFolder = "C:\NewFolder"
$Items = (Get-ChildItem -Path $SourceFolder -filter *.txt -Recurse | Where-Object LastWriteTime -lt '1/11/2021').Name
foreach ($Item in $Items)
{
    Try {
        Get-ChildItem -Path "$SourceFolder\$Item" | Move-Item -Destination $DestinationFolder
        Write-Host "$Item file moved to $DestinationFolder folder."
        }
    Catch
        {
        Write-Host "$Item file could not be moved to $DestinationFolder folder."
        }
}

 

Best Regards.

@AngeloLobo_79 Did our answers help ? @hasanemresatilmis included the file move part, I didn't because you said you already had that part ;) 

Hi @Harm_Veenstra,

 

Yes. I wanted it to be all in one script so that people who don't know the move command can benefit from it. :)