将两个最近的文件复制到新目录 [英] Copy the two most recent files to new dir

查看:179
本文介绍了将两个最近的文件复制到新目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个VBScript或.bat文件,将目录a中特定扩展名 *。sch 的两个最新文件移动到其他目录。

I would like to write a VBScript or .bat file to move the two most recent files of a specific extension *.sch in directory a to a different directory.

我已经尝试过 $ newest 如何找到第二个最新的?

I have experimented with $newest How do I find second newest?

感谢

推荐答案

在VBScript中,

In VBScript you could do it like this:

src = "C:\source\folder"
dst = "C:\destination\folder"

Set fso = CreateObject("Scripting.FileSystemObject")

mostRecent = Array(Nothing, Nothing)

For Each f In fso.GetFolder(src).Files
  If LCase(fso.GetExtensionName(f.Name)) = "sch" Then
    If mostRecent(0) Is Nothing Then
      Set mostRecent(0) = f
    ElseIf f.DateLastModified > mostRecent(0).DateLastModified Then
      Set mostRecent(1) = mostRecent(0)
      Set mostRecent(0) = f
    ElseIf mostRecent(1) Is Nothing Or f.DateLastModified > mostRecent(1).DateLastModified Then
      Set mostRecent(1) = f
    End If
  End If
Next

For i=0 To 1
  If Not mostRecent(i) Is Nothing Then mostRecent(i).Copy dst & "\"
Next

这篇关于将两个最近的文件复制到新目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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