Hi,
I am trying attached script but it doesn’t work well. Everything is OK except line with Robocopy.
I don’t know what parameters I should use.
I need copy the newest file from each folder and subfolders to destinations with the same folder name on another dsic.
I have no idea how to use robocopy in the right way. I don't know where I make a mistake.
I have spent many hours but without effect.
Excuse my bad English, please.
Thank you for your helpfulness
Josef
$Path = 'S:\0test' #Root path to look for files
$DestinationPath = "C:\"
#Grab a recursive list of all subfolders = seznam složek a podsložek
$SubFolders = dir $Path -Recurse | Where-Object {$_.PSIsContainer} | ForEach-Object -Process {$_.FullName}
#Iterate through the list of subfolders and grab the first file in each
ForEach ($Folder in $SubFolders)
{
$FullFileName = dir $Folder | Where-Object {!$_.PSIsContainer} | Sort-Object {$_.LastWriteTime} -Descending | Select-Object -First 1
#For every file grab it's location and output the robocopy command ready for use
ForEach ($File in $FullFileName)
{
$FilePath = $File.DirectoryName
$FileName = $File.Name
robocopy $FilePath $DestinationPath $FileName /S /R:6 /W:30 /Z
}
}