3
1

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.

[バッチファイル] ファイル名に含まれる日付を更新する

Posted at

”ほげほげ計画書_20170605.docx”のようにファイル名に含まれる日付だけを更新したいときに役立つバッチファイルの紹介です。

バッチファイル本体

date_update.bat
@echo off
rem *****************************************************************
rem ファイル名に含まれる日付を今日の日付に更新するバッチファイル
rem 前提条件
rem - ファイル名の後ろ8文字(YYYYMMDD)を今日の日付に更新する
rem *****************************************************************

:LOOP_START
if "%1" == "" goto LOOP_END
set filename=%~n1

rem %date 日付(YYYY/MM/DD)の'/'(スラッシュ)を取り除く
set today=%date:/=%

rem 後ろ8文字を今日の日付に更新
copy %1 %filename:~0,-8%%today%%~x1

shift
goto :LOOP_START

:LOOP_END
exit

使い方

・date_update.bat (アイコン) に対象のファイルをドラッグすると、今日の日付に更新されたファイルが作成されます。
・元のファイルが要らない場合、copy を rename に変えればOK
・複数ファイルを選択してドラッグしてもOK

3
1
3

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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?