Freigeben über


[PowerShell] ハッシュ変数の活用 - フォルダの同期

Windows PowerShell ???????????????????????????????????????????????????????

???????????????

  • 2???????????????????????????
  • folder2 ??00002.docx, 00003.docx ?2?????????????
  • ???? folder1 ????????????????????????????????

imageimage

???????????????????????????PowerShell ?????????????????????????

?????????????????????????????????????????????

PS> $person = @{ ??=”????”; ??=35; }

PS> $person["??"]
????
PS> $person["??"]
35

??????????????????????????????????

??????????????????????

PS> $f = @{}
PS> dir e:\tmp\folder2 | foreach { $f[$_.name] = $true }
PS> $f

Name                           Value
----                           -----
00005.docx                     True
00001.docx                     True
00004.docx                     True

  • @{} ????????? $f ??????
  • ????? folder2 ????????????????????????????$true ??? boolean ???????????????
  • $f ????????????3??????????????

folder2 ???????????????????$f ??????????????????????? True ??????????????????????????

PS> $f["00001.docx"]
True
PS> $f["00002.docx"]
PS>

??????????????????? folder1 ?????????

PS> dir e:\tmp\folder1 | foreach {if (!$f[$_.name]) { $_.name }}
00002.docx
00003.docx

  • ?????????????? folder1 ???????????????(dir)
  • ?????????????????$f ????????
  • ?? folder2 ??????????True ???????
  • ?????????????????! ???? True ??????? {} ????????
  • ????????????????????????

??????????????????????????????????????????????????????