繁体   English   中英

排除文件的最大上次修改日期

[英]exclude the files for max last modified date

文件需要从四个文件夹中移出...在此方法中如何使用逻辑来排除文件的最大上次修改日期

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

在这种情况下,要排除的文件1和要移至D:\\ven\\one\\two1 folder ...。需要简单的代码,谢谢

在PowerShell中,这很容易。 将以下代码保存在诸如keeplast.ps1的文件中。

目前尚不清楚为什么使用/ XD参数。

按LastWriteTime降序排序,然后跳过第一个条目,将产生其他文件名。 当您对完成正确的移动感到满意时,请从Move-Item cmdlet中删除-WhatIf

$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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM