PoshCode Archive  Hex Artifact Content

Artifact 26292ca81f1055da322f174500dfc99d2dd9cc402fb4c1a42d7a73b488003ca2:

  • File copy-data.ps1 — part of check-in [0f6d0271ef] at 2018-06-10 12:56:26 on branch trunk — Copy Data between Folders including a Progressbar (user: mazakane size: 672)

0000: 23 20 65 6e 63 6f 64 69 6e 67 3a 20 61 73 63 69  # encoding: asci
0010: 69 0d 0a 23 20 61 70 69 3a 20 70 6f 77 65 72 73  i..# api: powers
0020: 68 65 6c 6c 0d 0a 23 20 74 69 74 6c 65 3a 20 63  hell..# title: c
0030: 6f 70 79 2d 64 61 74 61 0d 0a 23 20 64 65 73 63  opy-data..# desc
0040: 72 69 70 74 69 6f 6e 3a 20 43 6f 70 79 20 44 61  ription: Copy Da
0050: 74 61 20 62 65 74 77 65 65 6e 20 46 6f 6c 64 65  ta between Folde
0060: 72 73 20 69 6e 63 6c 75 64 69 6e 67 20 61 20 50  rs including a P
0070: 72 6f 67 72 65 73 73 62 61 72 0d 0a 23 20 76 65  rogressbar..# ve
0080: 72 73 69 6f 6e 3a 20 30 2e 31 0d 0a 23 20 74 79  rsion: 0.1..# ty
0090: 70 65 3a 20 66 75 6e 63 74 69 6f 6e 0d 0a 23 20  pe: function..# 
00a0: 61 75 74 68 6f 72 3a 20 6d 61 7a 61 6b 61 6e 65  author: mazakane
00b0: 0d 0a 23 20 6c 69 63 65 6e 73 65 3a 20 43 43 30  ..# license: CC0
00c0: 0d 0a 23 20 66 75 6e 63 74 69 6f 6e 3a 20 63 6f  ..# function: co
00d0: 70 79 2d 64 61 74 61 0d 0a 23 20 78 2d 70 6f 73  py-data..# x-pos
00e0: 68 63 6f 64 65 2d 69 64 3a 20 31 31 30 33 0d 0a  hcode-id: 1103..
00f0: 23 20 78 2d 61 72 63 68 69 76 65 64 3a 20 32 30  # x-archived: 20
0100: 30 39 2d 30 35 2d 31 39 54 30 36 3a 34 31 3a 34  09-05-19T06:41:4
0110: 34 0d 0a 23 0d 0a 23 0d 0a 66 75 6e 63 74 69 6f  4..#..#..functio
0120: 6e 20 63 6f 70 79 2d 64 61 74 61 20 7b 0d 0a 09  n copy-data {...
0130: 70 61 72 61 6d 28 24 73 6f 75 72 63 65 2c 20 24  param($source, $
0140: 64 65 73 74 29 0d 0a 09 24 63 6f 75 6e 74 65 72  dest)...$counter
0150: 20 3d 20 30 0d 0a 09 24 66 69 6c 65 73 20 3d 20   = 0...$files = 
0160: 47 65 74 2d 43 68 69 6c 64 49 74 65 6d 20 24 73  Get-ChildItem $s
0170: 6f 75 72 63 65 20 2d 46 6f 72 63 65 20 2d 52 65  ource -Force -Re
0180: 63 75 72 73 65 0d 0a 09 66 6f 72 65 61 63 68 28  curse...foreach(
0190: 24 66 69 6c 65 20 69 6e 20 24 66 69 6c 65 73 29  $file in $files)
01a0: 0d 0a 09 09 7b 0d 0a 09 09 24 73 74 61 74 75 73  ....{....$status
01b0: 20 3d 20 22 43 6f 70 79 69 6e 67 20 66 69 6c 65   = "Copying file
01c0: 20 7b 30 7d 20 6f 66 20 7b 31 7d 3a 20 7b 32 7d   {0} of {1}: {2}
01d0: 22 20 2d 66 20 24 63 6f 75 6e 74 65 72 2c 20 24  " -f $counter, $
01e0: 66 69 6c 65 73 2e 63 6f 75 6e 74 2c 20 24 66 69  files.count, $fi
01f0: 6c 65 2e 6e 61 6d 65 0d 0a 09 09 57 72 69 74 65  le.name....Write
0200: 2d 50 72 6f 67 72 65 73 73 20 2d 41 63 74 69 76  -Progress -Activ
0210: 69 74 79 20 22 43 6f 70 79 6e 67 20 46 69 6c 65  ity "Copyng File
0220: 73 22 20 2d 53 74 61 74 75 73 20 24 73 74 61 74  s" -Status $stat
0230: 75 73 20 2d 50 65 72 63 65 6e 74 43 6f 6d 70 6c  us -PercentCompl
0240: 65 74 65 20 28 24 63 6f 75 6e 74 65 72 2f 24 66  ete ($counter/$f
0250: 69 6c 65 73 2e 63 6f 75 6e 74 20 2a 20 31 30 30  iles.count * 100
0260: 29 0d 0a 09 09 43 6f 70 79 2d 49 74 65 6d 20 24  )....Copy-Item $
0270: 66 69 6c 65 2e 70 73 70 61 74 68 20 24 64 65 73  file.pspath $des
0280: 74 20 2d 46 6f 72 63 65 0d 0a 09 09 24 63 6f 75  t -Force....$cou
0290: 6e 74 65 72 2b 2b 0d 0a 09 09 7d 0d 0a 7d 0d 0a  nter++....}..}..