Get-ChildItem 到 Move-Item - 找不到路径 [英] Get-ChildItem to Move-Item - path not found

查看:36
本文介绍了Get-ChildItem 到 Move-Item - 找不到路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我的旧日志文件移动到 yyyy\MM\dd 文件夹结构

I try to move my old logfiles to a yyyy\MM\dd folder structure by

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

但我收到一个找不到路径的错误.

but i get a path-not-found error.

更新

源路径似乎不是问题.看起来在 Move-Item 上使用 -Force 不会创建丢失的目标目录.

The source path does not seem to be the problem. It looks like using -Force on Move-Item does not create missing destination directories.

子问题:如果没有 Get-ChildItem 也能做到吗?

sub question: Could the same be done without Get-ChildItem?

推荐答案

就我发现移动日志的提议方式实际上很有趣,我决定完成任务:

As far as I found the proposed way of moving logs practically 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)"
}

这篇关于Get-ChildItem 到 Move-Item - 找不到路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆