本文介绍了有没有办法在powershell中使用等效的touch来更新文件的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我经常使用 unix 命令touch"来更新系统中任何新获取/下载文件的时间戳.很多时候,现有文件的时间戳很旧,因此它可能会在系统中丢失.在 MS-Windows powershell 中有没有办法做到这一点.我有 powershell 5 和 powershell 6.
I use the unix command 'touch' a lot to update time-stamps of any new acquired/downloaded file in my system. Many a times the time-stamp of the existing file is old so it can get lost in the system. Is there a way in MS-Windows powershell to do so. I have both powershell 5 as well as powershell 6.
推荐答案
可以使用
$file = Get-Item C:\Intel\Logs\IntelCpHDCPSvc.log
$file.LastWriteTime = (Get-Date)
或者 CreationTime 或 LastAccessTime,如果您愿意.
Or CreationTime or LastAcccessTime, if you prefer.
作为函数
Function UpdateFileLastWriteTimeToToday() {
Param ($FileName)
$file = Get-Item $FileName
Echo "Current last write time: " $file.LastWriteTime
$file.LastWriteTime = (Get-Date)
Echo "New last write time: " $file.LastWriteTime
}
#How to use
UpdateFileLastWriteTimeToToday -FileName C:\Intel\Logs\IntelGFX.Log
随着输出
Current last write time:
Tuesday, April 16, 2019 1:09:49 PM
New last write time:
Monday, November 4, 2019 9:59:55 AM
这篇关于有没有办法在powershell中使用等效的touch来更新文件的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!