2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerShell 1行でフォルダ内のすべてのファイル名の先頭に更新日時を入れる

Last updated at Posted at 2025-02-01

写真など、たくさんのファイルをファイル名の重複なく、かつ日付でソートしやすいようにファイル名の先頭に日付の固定長文字列をまとめて追加できる1行スクリプトを作成しました。日常使いのメモとして残します。

ファイルが入っているフォルダをカレントフォルダーにしてPowerShellターミナルを開き、以下の一行をコピペしてEnterキーを押します。

rename.ps1
(Get-ChildItem -File .) | Rename-Item -NewName {$_ -replace "^", $_.LastWriteTime.ToString("yyyyMMdd")}

実行イメージ

実行のイメージはこちら。
image.png

これで、カレントフォルダーのすべてのファイルのファイル名の先頭に、各ファイルの最終更新日時を表す8文字の数字が追加されます。

実行前
file01.png
file02.png
file03.png
file04.png
file05.png
file06.png
file07.png
file08.png
実行後
20250201file01.png
20250201file02.png
20250201file03.png
20250201file04.png
20250201file05.png
20250201file06.png
20250201file07.png
20250201file08.png
2
7
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
2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?