我怎么能覆盖"修改&QUOT日期;与"创建日期"在Windows? [英] How can I overwrite "Date Modified" with "Date Created" in Windows?
问题描述
我有运行Windows服务器的系统,我有机会获得PowerShell中,VBA等。
I have a system running Windows server and I have access to Powershell, VBA etc.
我需要一种方法来从属性创建日期覆盖与日期目录中的修改日期的所有文件的属性。有大约1百万个文件需要跨10000左右子目录进行更新,这岔开一个主目录。
I need a way to overwrite the "Date Modified" attribute of all files in a directory with the date from the "Date Created" attribute. There are approx 1 million files that need to be updated across 10'000 or so subdirectories, which branch off one master directory.
有一个简单的方式与命令行或PowerShell的等?
Is there a simple way to do this with either command line or Powershell etc?
推荐答案
这是一个混合的批处理/ javascript文件(保存为一批,每例如 touch.cmd
)这将重置所有文件的修改日期时间起始文件夹下,将其设置为同一个文件的创建日期时间。
This is an hybrid batch/javascript file (save it as batch, per example touch.cmd
) that will reset the modification datetime of all the files under a starting folder, setting it to the creation datetime of the same file.
@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);
这篇关于我怎么能覆盖"修改&QUOT日期;与"创建日期"在Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!