【问题标题】:Copy latest 2 files using Windows batch script使用 Windows 批处理脚本复制最新的 2 个文件
【发布时间】:2013-03-01 12:38:30
【问题描述】:

相关:How to get the most recent file using a batch script in windows

我想使用 Windows 批处理脚本从目录中复制最新的 2 个文件。

【问题讨论】:

    标签: windows batch-file


    【解决方案1】:
    @ECHO OFF
    SETLOCAL
    SET transfer=xx
    FOR /f "delims=" %%i IN ('dir/b/a-d/o-d *.*') DO IF DEFINED transfer CALL SET transfer=%%transfer:~1%%&ECHO %%i
    

    只需将 TRANSFER 设置为 #transfers 的长度即可执行;显然用适当的 COPY 命令替换 echo %%i

    【讨论】:

      【解决方案2】:

      我的版本基于Peter Wright的回答...

      @ECHO OFF
      setlocal EnableDelayedExpansion
      set j=0
      
      FOR /f "delims=" %%i IN ('dir /b /a-d /o-d *.*') DO (
          echo %%i
          set /A j=j+1
          if !j! geq 2 (
              goto :end
          )
      )
      :end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-08
        • 1970-01-01
        • 1970-01-01
        • 2019-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多