1
0

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 3 years have passed since last update.

windows forfilesコマンド ディレクトリ操作 動作確認環境構築

Last updated at Posted at 2020-09-04

forfilesコマンドを使って、最終更新日時の異なるフォルダとファイルに対し、いろいろ動作を確認してみたかったので、powershell にて試験用のディレクトリ構成を簡易に作り出すコマンドを作りました。
powershell にて下図の構成を一発で作れます。
※("yyyy/mm/dd")は、最終更新日時

こんな感じの動作環境を即興で作れます。

test/
 FOLDER_1/("2020/06/25 00:00:00")
      FORDER_A/("2020/06/25 00:00:00")
          text_a.txt("2020/06/25 00:00:00")
          text_b.txt("2020/07/25 00:00:00")
          text_c.txt("2020/08/25 00:00:00")
      FORDER_B/("2020/07/25 00:00:00")
      FORDER_C/("2020/08/25 00:00:00")
      text_A.txt("2020/06/25 00:00:00")
      text_B.txt("2020/07/25 00:00:00")
      text_C.txt("2020/08/25 00:00:00")
 FOLDER_2/("2020/07/25 00:00:00")
 FOLDER_3/("2020/08/25 00:00:00")
 text_1.txt("2020/06/25 00:00:00")
 text_2.txt("2020/07/25 00:00:00")
 text_3.txt("2020/08/25 00:00:00")

作成の為のpowershell用コマンド
New-Item FOLDER_1 -itemType Directory
New-Item FOLDER_2 -itemType Directory
New-Item FOLDER_3 -itemType Directory
New-Item text_1.txt -type file
New-Item text_2.txt -type file
New-Item text_3.txt -type file
New-Item FOLDER_1\FOLDER_A -itemType Directory
New-Item FOLDER_1\FOLDER_B -itemType Directory
New-Item FOLDER_1\FOLDER_C -itemType Directory
New-Item FOLDER_1\text_A.txt -type file
New-Item FOLDER_1\text_B.txt -type file
New-Item FOLDER_1\text_C.txt -type file
New-Item FOLDER_1\FOLDER_A\text_a.txt -type file
New-Item FOLDER_1\FOLDER_A\text_b.txt -type file
New-Item FOLDER_1\FOLDER_A\text_c.txt -type file
Set-ItemProperty FOLDER_1  -Name LastWriteTime -Value "2020/06/25 00:00:00"
Set-ItemProperty FOLDER_2  -Name LastWriteTime -Value "2020/07/25 00:00:00"
Set-ItemProperty FOLDER_3  -Name LastWriteTime -Value "2020/08/25 00:00:00"
Set-ItemProperty text_1.txt -Name LastWriteTime -Value "2020/06/25 00:00:00"
Set-ItemProperty text_2.txt -Name LastWriteTime -Value "2020/07/25 00:00:00"
Set-ItemProperty text_3.txt -Name LastWriteTime -Value "2020/08/25 00:00:00"
Set-ItemProperty FOLDER_1\FOLDER_A -Name LastWriteTime -Value "2020/06/25 00:00:00"
Set-ItemProperty FOLDER_1\FOLDER_B -Name LastWriteTime -Value "2020/07/25 00:00:00"
Set-ItemProperty FOLDER_1\FOLDER_C -Name LastWriteTime -Value "2020/08/25 00:00:00"
Set-ItemProperty FOLDER_1\text_A.txt -Name LastWriteTime -Value "2020/06/25 00:00:00"
Set-ItemProperty FOLDER_1\text_B.txt -Name LastWriteTime -Value "2020/07/25 00:00:00"
Set-ItemProperty FOLDER_1\text_C.txt -Name LastWriteTime -Value "2020/08/25 00:00:00"
Set-ItemProperty FOLDER_1\FOLDER_A\text_a.txt -Name LastWriteTime -Value "2020/06/25 00:00:00"
Set-ItemProperty FOLDER_1\FOLDER_A\text_b.txt -Name LastWriteTime -Value "2020/07/25 00:00:00"
Set-ItemProperty FOLDER_1\FOLDER_A\text_c.txt -Name LastWriteTime -Value "2020/08/25 00:00:00"
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?