Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. [string] $FileDirectory = "C:tempMove by headerinput";
  2. [string] $OutputPathHeat = "C:tempMove by headerHeatMeter";
  3. [string] $OutputPathWater = "C:tempMove by headerWaterMeter";
  4. [string] $OutputPathOther = "C:tempMove by headerOther";
  5.  
  6. foreach ($FilePath in Get-ChildItem $FileDirectory | Select-Object -
  7. ExpandProperty
  8. FullName)
  9. {
  10. [string] $Header = Get-Content $FilePath -First 1
  11.  
  12. if ($Header -match '#serial-number;device-identification;created;value-
  13. data-
  14. count;act-duration,second(s),inst-value,0,0,0;avg-
  15. duration,second(s),inst-value,0,0,0;energy,Wh,inst-
  16. value,0,0,0;volume,m3,inst-value,0,0,0.*') {
  17. Move-Item $FilePath $OutputPathHeat
  18. } elseif ($Header -match '#serial-number;device-
  19. identification;created;value-data-
  20. count;fabrication-no,,inst-
  21. value,0,0,0;datetime,,inst-
  22. value,0,0,0;volume,m3,inst-value,0,0,0.*') {
  23. Move-Item $FilePath $OutputPathWater
  24. } else {
  25. Move-Item $FilePath $OutputPathOther
  26. }
  27. }
  28.  
  29. $RootDirectory = 'C:tempMove by header'
  30. $InputDirectory = Join-Path -Path $RootDirectory -ChildPath 'input'
  31. $OutputPathHeat = Join-Path -Path $RootDirectory -ChildPath 'HeatMeter'
  32. $OutputPathWater = Join-Path -Path $RootDirectory -ChildPath 'WaterMeter'
  33. $OutputPathOther = Join-Path -Path $RootDirectory -ChildPath 'Other'
  34.  
  35. # get an array of Full path and filenames of the files in the input directory.
  36. # because you want files only, add the '-File' switch.
  37. # if you're on PowerShell version below 3.0, use:
  38. # (Get-ChildItem $InputDirectory | Where-Object { !$_.PSIsContainer })
  39. foreach ($FilePath in (Get-ChildItem $InputDirectory -File) | Select-Object -ExpandProperty FullName) {
  40. $Header = Get-Content $FilePath -First 1
  41.  
  42. # test for a string in the header line that distincts it from the other files
  43. if ($Header -match ';energy,Wh,') {
  44. # the substring ';energy,Wh,' defines this file as a 'HeatMeter' file
  45. Move-Item -Path $FilePath -Destination $OutputPathHeat
  46. }
  47. elseif ($Header -match ';fabrication-no,,') {
  48. # the substring ';fabrication-no,,' defines this file as a 'WaterMeter' file
  49. Move-Item -Path $FilePath -Destination $OutputPathWater
  50. }
  51. else {
  52. # if both key substrings above did not match, move to the 'Other' directory
  53. Move-Item -Path $FilePath -Destination $OutputPathOther
  54. }
  55. }
  56.  
  57. # test for a string in the header line that distincts it from the other files
  58. switch -Regex ($Header) {
  59. # the substring ';energy,Wh,' defines this file as a 'HeatMeter' file
  60. ';energy,Wh,' { Move-Item -Path $FilePath -Destination $OutputPathHeat; break }
  61.  
  62. # the substring ';fabrication-no,,' defines this file as a 'WaterMeter' file
  63. ';fabrication-no,,' { Move-Item -Path $FilePath -Destination $OutputPathWater; break }
  64.  
  65. # if both key substrings above did not match, move to the 'Other' directory
  66. default { Move-Item -Path $FilePath -Destination $OutputPathOther }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement