Hello,
I am busy with making a script that will search for the latest file with a specific extension.
After powershell found the file it needs to copy that file by using robocopy !
I have made this code:
$dir = "C:\robocopy"
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1 | Where {$_.name -Match "test*" -and $_.extension -eq ".txt" }
$latest.name
$source = "$dir\$latest"
Write-Host "$source"
$Destination= "D:\"
robocopy $source $Destination
But this is the result i get :
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1 | Where {$_.name -Match "test*" -and $_.extension -eq ".txt" }
$latest.name
$source = "$dir\$latest"
Write-Host "$source"
$Destination= "D:\"
robocopy $source $Destination
C:\robocopy\
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Fri Nov 22 11:35:07 2013
Source : C:\robocopy\
Dest : D:\
Files : *.*
Options : *.* /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
5 C:\robocopy\
New File 0 test.cmd
100%
New File 0 test1.txt
100%
New File 0 test.txt
100%
New File 18 test2.txt
0%
100%
New File 0 test3.txt
100%
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 45
Files : 5 5 1 0 0 9
Bytes : 1.989 g 18 1.989 g 0 0 485.51 m
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 666 Bytes/sec.
Speed : 0.038 MegaBytes/min.
Ended : Fri Nov 22 11:35:07 2013So the problem is already that it doesn't take the right file.
now it will just coppy all files from it .
Please help me.
Regards,
Dirk