我如何可以覆盖在Windows的“创建日期”,“修改日期”?(How can I overwrite

2019-10-20 12:40发布

我有一个系统运行Windows服务器,我有机会获得PowerShell中,VBA等。

我需要一种方法来从属性“创建日期”覆盖与日期目录中的“修改日期”的所有文件的属性。 有大约1个百万个文件需要跨10000个左右子目录进行更新,其中岔开一个主目录。

有一个简单的方法与命令行或Powershell的等做到这一点?

Answer 1:

这是一个混合料/ JavaScript文件(它保存为批次,按实施例touch.cmd )将重置起始文件夹下的所有文件的修改日期时间,将其设置到相同的文件的创建日期时间。

@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************

    setlocal enableextensions disabledelayedexpansion
    set "targetFolder=%~1"
    if not defined targetFolder set "targetFolder=%cd%"

    rem call javascript part of batch file
    cscript //nologo //e:Javascript "%~f0" /startFolder:"%targetFolder%"

    rem End of batch area. End batch execution before reaching js zone
    endlocal
    exit /b

@end
// **** Javascript zone *****************************************************

    if (!WScript.Arguments.Named.Exists('startFolder')) {
        // if no start folder is given, leave
        WScript.Quit(1);
    };

    // retrieve start folder
    var startFolder = WScript.Arguments.Named.Item('startFolder');

    // instantiate needed components
    var fso = WScript.CreateObject('Scripting.FileSystemObject');
    var shell = WScript.CreateObject('Shell.Application');

    // recursive function to set the ModifyDate to the CreationDate
    (function processFolder( folderPath ){
        // test for valid paths
        folderPath = fso.GetAbsolutePathName((folderPath || '' ));
        if (!fso.FolderExists(folderPath)) return ;
        // retrieve a reference to the folder namespace
        var folderNS = shell.NameSpace(folderPath);
        // process files inside this folder
        for (var files = new Enumerator(fso.GetFolder( folderPath ).Files ); !files.atEnd() ; files.moveNext()){
            var file = files.item();
            WScript.StdOut.WriteLine( file.Path );
            folderNS.ParseName( file.Name ).ModifyDate = file.DateCreated;
        };
        // process files under child folders
        for (var folders = new Enumerator(fso.GetFolder( folderPath ).SubFolders); !folders.atEnd() ; folders.moveNext()){
            processFolder( folders.item().Path );
        };
    })( startFolder );

    WScript.Quit(0);


文章来源: How can I overwrite “Date Modified” with “Date Created” in Windows?