Aqui está escrito no PowerShell 3.
#Set Location to Folder
Set-Location -Path "C:\Personal Folders"
#Check If The Folder "new_dat" exists, if it doesnt, create it
if(!(Test-Path -Path "new_dat"))
{
New-Item -Name "new_dat" -ItemType Directory
}
#Get All The Folders Except "new_dat"
$Folders = Get-ChildItem -Directory | Where-Object {$_.Name -ne "new_dat"}
#This Is Where The Magic Happens
foreach($Folder in $Folders)
{
Get-ChildItem -Path $Folder.FullName -Filter *.dat | Move-Item -Destination (Join-Path -ChildPath ([System.IO.Path]::GetFileNameWithoutExtension($Folder.Name) + "_dat.dat") -Path "C:\Personal Folders\new_dat" )
}
- Instale o PowerShell 3
- Coloque isso em um arquivo de texto e chame-o de Move.ps1
- Configure uma tarefa agendada para executá-la a cada X horas ou qualquer outra