📎 AI Summary:
In this WindowsForum thread, the original poster seeks help for automating the transfer of pet-related .txt files from a local C: drive to specific network folders based on filename prefixes. A responder provides a simple PowerShell script that moves files matching "dogs*.txt" and "cats*.txt" to designated network directories, offering a straightforward solution. The overall tone is collaborative, with the community providing practical scripting advice to streamline the file management process.

Patters

New Member
Joined
Jun 10, 2019
Messages
1
Thread Author #1
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
 

Solution
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\"
    }
}

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
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\"
    }
}
 

Solution