-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ps1
41 lines (33 loc) · 1.65 KB
/
main.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
param (
# Путь к папке, в которой нужно переименовать xml'ки
[string] $path = $env:USERPROFILE + "\desktop\extracts-downloaded",
# Нужно ли выписки раскаладывать по папкам?
[bool] $isMoveToFolder = $true
)
Set-Location ($MyInvocation.MyCommand.Path | Split-Path -Parent)
. .\RenameTable.ps1
[string] $renTableName = $path + "\_renameTable.csv"
[DateTime] $errorDate = [datetime]::ParseExact("1990-01-01","yyyy-MM-dd",[Globalization.CultureInfo]::CreateSpecificCulture('ru-RU'))
if (Test-Path -Path $renTableName){
if ($isMoveToFolder){
$extracts = Import-Csv ($renTableName) -Encoding UTF8 | where {$_.CadNum -and ($_.Date -ne $errorDate -and $_.Date)}
foreach ($elem in $extracts) {
If(!(Test-Path $elem.NewFolder)){
New-Item -ItemType Directory -Force -Path $elem.NewFolder | Out-Null
}
if ($elem.Path -ne ($elem.NewFolder + '\' + $elem.NewShortName)){
Move-Item -LiteralPath $elem.Path -Destination ($elem.NewFolder + '\' + $elem.NewShortName) -Force
Write-Host ("Move to: " + $elem.NewFolder + '\' + $elem.NewShortName)
}
}
}
else {
Import-Csv ($renTableName) -Encoding UTF8 | where {$_.CadNum -and ($_.Date -ne $errorDate -and $_.Date)} | foreach { Rename-Item -LiteralPath $_.Path -NewName $_.NewBigName}
}
Remove-Item $renTableName -Force
}
else
{
[array] $files = ls $path -Filter *.xml -Recurs
Generate-ExtractRenameTable($files) | Export-Csv -Path ($renTableName) -Encoding UTF8
}