Get-ChildItem for Move-Item - path not found

I am trying to move old log files to the yyyy \ MM \ dd folder structure on

Get-ChildItem . -Recurse -Include *.log | 
Move-Item -Dest {"D:\Archive\{0:yyyy\\MM\\dd}\{1}" -f $_.LastWriteTime, $_.Name} -Force

but I get an error not found in the path.

Update

The source path does not seem to be a problem. It seems that using -Forceon Move-Itemdoes not create missing destination directories.


additional question : Is it possible to do this without Get-ChildItem?

+3
source share
2 answers

As far as I found the proposed method for moving logs almost interesting, I decided to complete the task:

Get-ChildItem . -Recurse -Include *.log |
Move-Item -Force -Destination {
    $dir = "C:\Temp\{0:yyyy\\MM\\dd}" -f $_.LastWriteTime
    $null = mkdir $dir -Force
    "$dir\$($_.Name)"
}
+3
source

, "some.log" - "D:\Archive\2010\04\23\some.log" "D:\Archive\2010\04\23" . Move-Item . ?

+1

Source: https://habr.com/ru/post/1742457/


All Articles