[英]Windows batch file: move files older than X minutes to a different directory using UnixUtils find command
I found the unixutils for Windows and am trying to use the find command to move files older than 30 minutes to a different directory. 我找到了适用于Windows的unixutils,并尝试使用find命令将30分钟以上的文件移动到另一个目录。
I have tried all of the following (also with \\ at the end of SourceDir and/or TargetDir) but get various errors that I'm pretty sure are due to unix using / to delimit directories and Windows using \\ to delimit directories: 我已经尝试了以下所有方法(在SourceDir和/或TargetDir的末尾也用\\进行了尝试),但是我敢肯定是由于使用/来分隔目录的unix和使用\\来分隔目录的Windows导致的各种错误:
find C:\SourceDir -name * -mmin +30 -type f -exec "move {} C:\TargetDir" ;
find C:\SourceDir -name * -mmin +30 -type f -exec "move {} C:\TargetDir" +
find C:\SourceDir -name * -mmin +30 -type f -execdir "move {} C:\TargetDir" ;
find C:\SourceDir -name * -mmin +30 -type f -execdir "move {} C:\TargetDir" +
Has anybody got this to work? 有人有这个工作吗?
I'm also not tied to using this utility - it just seemed like it would be easy to do. 我也不受使用此实用程序的束缚-似乎很容易做到。 I do have to do it via command line, though, as part of a scheduled job, and would very much prefer not to have to install any software.
不过,作为计划作业的一部分,我确实必须通过命令行来执行此操作,并且非常希望不必安装任何软件。 Copying standalone single file utilities is acceptable, though.
但是,可以复制独立的单个文件实用程序。
I believe Windows Powershell is available to me, as well. 我相信我也可以使用Windows Powershell。
Thanks! 谢谢!
I found somebody who helped me with Windows Powershell. 我找到了帮助Windows Powershell的人。 I thought I'd provide an update here in case it helps somebody else later.
我以为我会在这里提供更新,以防日后对他人有所帮助。
The following Powershell command does the same thing: 以下Powershell命令执行相同的操作:
get-childitem -Path "C:\SourceDir" -recurse | where-object {$_.LastWriteTime -le (get-date).AddMinutes(-30)} | move-item -destination "C:\TargetDir" -force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.