Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [string] $FileDirectory = "C:tempMove by headerinput";
- [string] $OutputPathHeat = "C:tempMove by headerHeatMeter";
- [string] $OutputPathWater = "C:tempMove by headerWaterMeter";
- [string] $OutputPathOther = "C:tempMove by headerOther";
- foreach ($FilePath in Get-ChildItem $FileDirectory | Select-Object -
- ExpandProperty
- FullName)
- {
- [string] $Header = Get-Content $FilePath -First 1
- if ($Header -match '#serial-number;device-identification;created;value-
- data-
- count;act-duration,second(s),inst-value,0,0,0;avg-
- duration,second(s),inst-value,0,0,0;energy,Wh,inst-
- value,0,0,0;volume,m3,inst-value,0,0,0.*') {
- Move-Item $FilePath $OutputPathHeat
- } elseif ($Header -match '#serial-number;device-
- identification;created;value-data-
- count;fabrication-no,,inst-
- value,0,0,0;datetime,,inst-
- value,0,0,0;volume,m3,inst-value,0,0,0.*') {
- Move-Item $FilePath $OutputPathWater
- } else {
- Move-Item $FilePath $OutputPathOther
- }
- }
- $RootDirectory = 'C:tempMove by header'
- $InputDirectory = Join-Path -Path $RootDirectory -ChildPath 'input'
- $OutputPathHeat = Join-Path -Path $RootDirectory -ChildPath 'HeatMeter'
- $OutputPathWater = Join-Path -Path $RootDirectory -ChildPath 'WaterMeter'
- $OutputPathOther = Join-Path -Path $RootDirectory -ChildPath 'Other'
- # get an array of Full path and filenames of the files in the input directory.
- # because you want files only, add the '-File' switch.
- # if you're on PowerShell version below 3.0, use:
- # (Get-ChildItem $InputDirectory | Where-Object { !$_.PSIsContainer })
- foreach ($FilePath in (Get-ChildItem $InputDirectory -File) | Select-Object -ExpandProperty FullName) {
- $Header = Get-Content $FilePath -First 1
- # test for a string in the header line that distincts it from the other files
- if ($Header -match ';energy,Wh,') {
- # the substring ';energy,Wh,' defines this file as a 'HeatMeter' file
- Move-Item -Path $FilePath -Destination $OutputPathHeat
- }
- elseif ($Header -match ';fabrication-no,,') {
- # the substring ';fabrication-no,,' defines this file as a 'WaterMeter' file
- Move-Item -Path $FilePath -Destination $OutputPathWater
- }
- else {
- # if both key substrings above did not match, move to the 'Other' directory
- Move-Item -Path $FilePath -Destination $OutputPathOther
- }
- }
- # test for a string in the header line that distincts it from the other files
- switch -Regex ($Header) {
- # the substring ';energy,Wh,' defines this file as a 'HeatMeter' file
- ';energy,Wh,' { Move-Item -Path $FilePath -Destination $OutputPathHeat; break }
- # the substring ';fabrication-no,,' defines this file as a 'WaterMeter' file
- ';fabrication-no,,' { Move-Item -Path $FilePath -Destination $OutputPathWater; break }
- # if both key substrings above did not match, move to the 'Other' directory
- default { Move-Item -Path $FilePath -Destination $OutputPathOther }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement