将文件移到31天后再移动到另一个驱动器 [英] Move Files older then 31 days to another drive

查看:147
本文介绍了将文件移到31天后再移动到另一个驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数移动{
#将所有超过31天的文件从源文件夹移动到目标
Get-Childitem -PathE:\source | Where-Object {$ _。LastWriteTime -lt(get-date).AddDays(-31)} |
ForEach {
Move-Item $ _。FullName -destinationF:\target-force -ErrorAction:SilentlyContinue
}
}

是大于2 - 3年的文件,但是当我运行脚本时,什么都不会移动到目标目录?什么是错的?

解决方案

我不知道这是否有很大的区别,而不是$。它需要$ _。



我试过这个脚本,它适用于我:

  get-childitem -PathE:\source| 
where-object {$ _。LastWriteTime -lt(get-date).AddDays(-31)} |
move-item -destinationF:\ target

需要一个foreach循环,因为这些对象将被传送到move-item命令

Function Move {
  #Moves all files older than 31 days old from the Source folder to the Target 
  Get-Childitem -Path "E:\source" | Where-Object { $_.LastWriteTime -lt (get-date).AddDays(-31)} |
  ForEach {
    Move-Item $_.FullName -destination "F:\target" -force -ErrorAction:SilentlyContinue
  }
}

in the source directory are files that are older than 2-3 years, but when i run the script nothing moves to the target directory ?! whats wrong ?

解决方案

I don't know if this makes much of a difference, but rather than $. it needs to be $_.

I tried this script and it works fine for me:

get-childitem -Path "E:\source" |
    where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} | 
    move-item -destination "F:\target"

Notice you don't need a foreach loop because the objects will be "piped" into the move-item command

这篇关于将文件移到31天后再移动到另一个驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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