windows - 排除最大上次修改日期的文件
问题描述
文件需要从四个文件夹中移动...如何使用逻辑排除文件的最大上次修改日期
robocopy D:\ven\one1\ D:\ven\one\two1\ /MOVE /xd D:\ven\one\ven_program_kl
举个例子
file1 last modified date:6/19/18 20:00
file2 last modified date:6/8/18 20:00
在这种情况下,要排除 file1 并将 file2 移至D:\ven\one\two1 folder
....需要简单的代码,谢谢
解决方案
这在 PowerShell 中很容易。将以下代码保存在文件中,例如keeplast.ps1
.
目前尚不清楚您为什么使用 /XD 参数。
按 LastWriteTime 降序排序,然后跳过第一个条目,将产生其他文件名。如果您对正确的移动操作感到满意,请-WhatIf
从Move-Item
cmdlet 中删除 。
$sourcedir = 'C:\src\t'
$destdir = $Env:TEMP
Get-ChildItem -File -Path $sourcedir |
Sort-Object -Property LastWriteTime -Descending |
Select-Object -Skip 1 |
Move-Item -Destination $destdir -WhatIf
如果必须从 cmd shell 运行它,请使用:
powershell -NoProfile -File .\keeplast.ps1
如果需要,可以创建一个 .bat 文件脚本。
@ECHO OFF
powershell -NoProfile -File .\keeplast.ps1
EXIT /B
推荐阅读
- vue.js - 如何将一个 v-model 的值适合另一个 v-model?
- swift - 如何在 Swift 中运行 shell 命令?
- javascript - 使用 .filter() 和 .map() 解决 Javascript 中的两个集合的交集
- java - 混淆代码时如何使用proguard-maven-plugin过滤所有maven依赖?
- sql-server - SQL 聚合数据以获取前 X
- python - 使用 labelimg 训练模型后找不到图像错误
- docker - 某些容器的 502 Bad Gateway 问题
- c# - 如何防止最小化父窗口关闭子窗口
- python - 使用 Jenkins 部署 python Flask 应用程序并执行它
- javascript - 两个 div 之间的 jQuery 冲突未按预期工作