1
2

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(ワンライナー)で日付&曜日の混合名の写真格納フォルダを31日分作成

Last updated at Posted at 2018-10-07

問題と課題

・デジカメとスマホの写真をパソコンに日付別フォルダに分けて移したい。その為にフォルダを沢山作成してきたがタイヘン。そこで、PowerShellで一括で作成してみた。

PowerShellのcode

foreach($i in 1..31){new-item ("2019_10_"+([string]$i).PadLeft(2,"0")+""+(Get-Date "2019/10/$i").ToString("ddd")+"_") -itemtype directory}

補足メモ

新規フォルダを一つ作成

new-item フォルダ名 -itemtype directory

31日分繰り返し

foreach($i in 1..31){繰り返す対象。$iは数値で使用可}

1~9日の1桁日の桁数を2桁にしたい。2桁はそのまま

([string]$i).PadLeft(2,"0")

漢字の曜日「月火水木金土日」を日付から入手したい

(Get-Date "2019/10/$i").ToString("ddd")

その他

要素は、括弧()で囲まないとダメらしい。

結果:Output

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2019/10/24      1:03                2019_10_01_
d-----       2019/10/24      1:03                2019_10_02_
d-----       2019/10/24      1:03                2019_10_03_
d-----       2019/10/24      1:03                2019_10_04_
d-----       2019/10/24      1:03                2019_10_05_
d-----       2019/10/24      1:03                2019_10_06_
d-----       2019/10/24      1:03                2019_10_07_
d-----       2019/10/24      1:03                2019_10_08_
d-----       2019/10/24      1:03                2019_10_09_
d-----       2019/10/24      1:03                2019_10_10_
d-----       2019/10/24      1:03                2019_10_11_
d-----       2019/10/24      1:03                2019_10_12_
d-----       2019/10/24      1:03                2019_10_13_
d-----       2019/10/24      1:03                2019_10_14_
d-----       2019/10/24      1:03                2019_10_15_
d-----       2019/10/24      1:03                2019_10_16_
d-----       2019/10/24      1:03                2019_10_17_
d-----       2019/10/24      1:03                2019_10_18_
d-----       2019/10/24      1:03                2019_10_19_
d-----       2019/10/24      1:03                2019_10_20_
d-----       2019/10/24      1:03                2019_10_21_
d-----       2019/10/24      1:03                2019_10_22_
d-----       2019/10/24      1:03                2019_10_23_
d-----       2019/10/24      1:03                2019_10_24_
d-----       2019/10/24      1:03                2019_10_25_
d-----       2019/10/24      1:03                2019_10_26_
d-----       2019/10/24      1:03                2019_10_27_
d-----       2019/10/24      1:03                2019_10_28_
d-----       2019/10/24      1:03                2019_10_29_
d-----       2019/10/24      1:03                2019_10_30_
d-----       2019/10/24      1:03                2019_10_31_
1
2
1

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?