6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellメモ ファイル更新日時変更(touch)

Last updated at Posted at 2016-10-06

概要

ファイルの更新日時(タイムスタンプ)を変更する方法。

書式

Set-ItemProperty -Path 【ファイルパス】 -Name LastWriteTime -Value $(Get-Date)
もっと短く
sp -path 【ファイルパス】 -n lastwritetime -va $(date)

実行例

sp -path .\hoge.txt -n lastwritetime -va $(date)

sp -path C:\Work\piyo.csv -n lastwritetime -va $(date)

# 任意の日付を設定する例
sp -path .\hoge.txt -n lastwritetime -va $(date '2016/10/06 22:30:45')

関数版

<#
.SYNOPSIS
    ファイル更新日変更

.DESCRIPTION
    指定したファイルの更新日を現在日付に設定する。

.PARAMETER path
    対象ファイルパス
# >
function touch([Parameter(Mandatory, ValueFromPipeline=$true)][string]$path)
{
    Set-ItemProperty -Path $path -Name LastWriteTime -Value $(Get-Date)
}

関数版の実行例

touch .\hoge.dat

動作確認した環境

  • PowerShell V4
  • PowerShell V5
6
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?