【问题标题】:Getting the file names of all the files that were modified in the last week using batch?使用批处理获取上周修改的所有文件的文件名?
【发布时间】:2014-05-02 13:34:07
【问题描述】:

我正在尝试获取某个目录(具有子目录)中上周修改过的文件的所有文件名。我知道下面的脚本返回每个子目录中最后修改的文件。是否可以用批处理脚本做我想做的事情?如果可能,应该对以下脚本进行哪些更改?在此先感谢:)

@echo off
setlocal EnableDelayedExpansion

for /D %%G in (*) do (
  echo %%G
  cd %%G\

    for /f "delims=" %%F in ('dir /b/a-d/tw') do (
      set last=%%F
    )  

  echo !last!
  cd..
  pause   
)

【问题讨论】:

  • 您是否首先在此处进行了基本搜索以查找以前的问题?尝试搜索[batch-file] find modified files(包括方括号),看看你能找到什么。
  • @ken 是的,我做到了.. 我只是不知道如何获取在上周修改过的文件。
  • 这些搜索结果中有几个提到获取修改日期(最旧的文件、上个月的文件、最新的文件)。我认为稍加努力可能会使其中一项对您有用。 (我们尽量不在这里重复问题。)
  • Here's a question 关于检查时间戳和删除超过 2 天的文件。它应该给你一个开始(将 2 天更改为 7,将 del 更改为 dir /s)。
  • stackoverflow.com/questions/7758987/… - 仍然是如何知道“上周”何时开始和结束。

标签: batch-file for-loop cmd directory


【解决方案1】:
/D    date          Selects files with a last modified date greater
                    than or equal to (+), or less than or equal to
                    (-), the specified date using the
                    "dd/MM/yyyy" format; or selects files with a
                    last modified date greater than or equal to (+)
                    the current date plus "dd" days, or less than or
                    equal to (-) the current date minus "dd" days. A
                    valid "dd" number of days can be any number in
                    the range of 0 - 32768.
                    "+" is taken as default sign if not specified.

查看文件 /?。有很多示例命令。

【讨论】:

  • 谢谢!我会调查的:)
【解决方案2】:

这里使用 Robocopy 提供列表。
过去 7 天的最新文件显示在底部,最旧的文件显示在顶部。

将文件夹变量更改为您需要检查的树。

@echo off
:: Do NOT remove /L from the robocopy line

    set "folder=d:\data"

for /f "tokens=1,2,*" %%a in ('robocopy "%folder%" "%folder%" *.* /L /s /maxage:7 /nocopy /is /njh /njs /ndl /nc /ns /ts ^|sort ') do echo %%c
pause

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 2011-03-02
    相关资源
    最近更新 更多