修改文件夹而不修改时间戳

Modifying folder without modifying timestamp

我想更改文件夹内容而不更改修改日期

我有时会对旧文件夹进行清理,尝试创建 space 或清理临时文件和死胡同,或者添加相关链接或标签以便于查找。当我这样做时,我不想将文件夹更改为 修改日期:今天 2015,因为我的文件夹按 修改日期 排序。 2010 年的项目应该保留其最后修改日期为 2010 年的时间戳,因为我只进行了元更改,而不是实际更改。

目前我使用SK Timestamp or Attribute Changer。在我想对其进行更改之前,我右键单击每个文件夹,我保持属性 window 打开,进行修改,然后点击应用覆盖原始时间戳。

我想更加自动化,例如在根文件夹 D:\Workspace 上设置 清理模式 和在我弹出该状态之前,子目录 Project2010Project2013...、Project2015

中的时间戳永远不会更改

或者至少能够在 2 个文件之间复制时间戳。就像 this answer 中提到的 @COPY /B %1+,, %1,但不是当前日期。 用法如:touch D:\Temp\Project2010\Source.txt Destination.ext

我在上面评论了一些建议——一个涉及修改系统的日期/时间,另一个涉及 robocopy。系统日期/时间有点麻烦,需要上网,robocopy /dcopy:t开关在我的测试中根本不起作用。

但我还是找到了更好的解决方案。使用 for 循环将文件夹的日期时间捕获到变量中。然后,在您进行任何更改后,使用 powershell 将文件夹的日期/时间恢复原样。

@echo off
setlocal

set "dir=path\to\directory"
for %%I in (%dir%) do set "datetime=%%~tI"

:: Do whatever deletions and other maintenance you want here.

:: Then after all changes have completed, reset the dir timestamp.
powershell -command "(Get-Item '%dir%').LastWriteTime=(Get-Date '%datetime%')"