简体   繁体   English

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

[英]Modifying folder without modifying timestamp

I'd like to change folder contents without having Date modified change. 我想更改文件夹内容而不更改日期

I sometimes do cleanup runs on old folders, trying to make space or clean up temp files and dead-ends, or adding relevant links or tags for findability. 有时,我会在旧文件夹上运行清理工作,试图腾出空间或清理临时文件和死胡同,或者添加相关链接或标签以提高可查找性。 When I do this, I don't want to change the folder to Date modified: today 2015 , because my folders are sorted by Date modified . 执行此操作时,我不想将文件夹更改为“ 修改日期:今天” ,因为我的文件夹按“ 修改日期”排序。 A project from 2010 should remain timestamped with its last modified date from 2010, because I've only made meta-changes, not actual changes. 2010年的项目应保留其2010年最后修改日期的时间戳,因为我仅进行了元更改,而不进行实际更改。

Currently I use SK Timestamp or Attribute Changer . 目前,我使用SK TimestampAttribute Changer I right click each folder before I want to make changes to it, I keep the Properties window open, make my modifications, then hit Apply to overwrite the original timestamps. 在我要对其进行更改之前,我右键单击每个文件夹,将“属性”窗口保持打开状态,进行修改,然后单击“应用”以覆盖原始时间戳。

I'd like to do it more automated, like set a Cleanup Mode on the root folder D:\\Workspace and until I pop that state no timestamps ever get changed in the subdirectories Project2010 , Project2013 ..., Project2015 我想使其更加自动化,例如在根文件夹D:\\Workspace上设置“ 清理模式 ”,直到弹出该状态,子目录Project2010Project2013 ..., Project2015中的时间戳都不会更改

Either that or at least be able to copy the timestamp between 2 files. 或者至少能够在2个文件之间复制时间戳。 Like in this answer that mentions @COPY /B %1+,, %1 , but not with current date. 像在此答案中提到@COPY /B %1+,, %1 ,但没有当前日期。 Usage like: touch D:\\Temp\\Project2010\\Source.txt Destination.ext 用法如下: touch D:\\Temp\\Project2010\\Source.txt Destination.ext

I had commented above with a couple of suggestions -- one involving modifying the system's date / time, and another involving robocopy . 上面,我提出了一些建议-一个涉及修改系统的日期/时间,另一个涉及robocopy The system date / time one is a bit of trouble and requires Internet access, and the robocopy /dcopy:t switch didn't work at all in my tests. 系统日期/时间有点麻烦,需要Internet访问,并且robocopy /dcopy:t开关在我的测试中根本不起作用。

But I found a better solution anyway. 但是我还是找到了更好的解决方案。 Use a for loop to capture the folder's date time to a variable. 使用for循环将文件夹的日期时间捕获到变量中。 Then after you've made whatever changes you wish, use powershell to put the folder's date / time back the way it was. 然后,在进行了所需的任何更改之后,请使用powershell将文件夹的日期/时间恢复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%')"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM