Windows 10 Automove script

Patters

New Member
Hi everyone

Was wondering if anyone can help me with this problem, of moving files off a c: drive to a network drive.

So at work we have a machine that outputs .txt files now as an example these files include data about ..pets so in the folder I have hundreds of files that are named similar to dogs_123456_10062019.txt then cats_123457_10062019.txt

Now the first number is a reference number than changes per .txt file that is created and the other is a date, as said I can have hundreds of these per day.

Now I have a network folder structure of Y:dogs & Y:cats and wanted a automated script that transfers all dog & cat text files to the corresponding network drive.

Is this possible?

Cheers
 
It would be pretty simply with powershell

Code:
# Change -Path C:\Test\ to the location the files need to be moved from with the trailing \

$Files = Get-ChildItem -Path C:\Test\ -Filter "*.txt" -Recurse

foreach($File in $Files)
{
    if ($File.Name -like "dogs*.txt")
    {
        Move-Item -Path $File.FullName -Destination "Y:\Dogs\"
    }
    elseif ($File.Name -like "cats*.txt")
    {
        Move-Item -Path $File.FullName -Destination "Y:\Cats\"
    }
}
 
Back
Top