Add-Type -AssemblyName Microsoft.VisualBasic
$pathTop = [Environment]::GetFolderPath('Desktop')
. .\Func_Files.ps1
. .\Func_Word.ps1
function RenameBK($pathBK){
WriteLog "Start Rename."
$CI = Get-ChildItem $pathBK -File -Name | sort { [string]$_ }
$cnt=0
foreach($strOld in $CI){
# 半角にする
$strNew = [Microsoft.VisualBasic.Strings]::StrConv( `
$strOld,[Microsoft.VisualBasic.VbStrConv]::Narrow)
# Replace
$strNew = $strNew.Replace("_","-").Replace(" ","").Replace("-.doc",".doc")
# 6文字目は"-"か"."
if($strNew.Length -ge 6){
$subs=$strNew.Substring(5,1)
if($subs -ne "-" -and $subs -ne "."){
$strNew=$strNew.Insert(5,"-")
}
}
# --間は消す,()は消す
$strNew=$strNew -replace '-.*-','-'
$strNew=$strNew -replace '\(.*\)',''
# Z追加
if($strNew -match '-\w\w\.'){
$strNew=$strNew.Replace("-","-z")
}
#Rename
if( ($strNew -match "^C\d{4}\.docx?$")-or($strNew -match "^C\d{4}-\w\w*.docx?$") ){
if($strOld -ne $strNew){
MyRename $strOld $strNew -RemoveByDate; $cnt++
}
}else{
WriteLog ($strOld + " not-match.")
}
}
WriteLog "Exec Rename $cnt Count.`r`n"
}
function RemoveBK($pathBK){
WriteLog "Start Remove."
$cntExec = 0;$cntError = 0
$CI= Get-ChildItem $pathBK -File -Name | sort -Descending
$nmKeep = ""
foreach($nm in $CI){
$ret=""
if($nm -match "C\d{4}.*\.docx?$"){
if( (MySubstring $nmKeep 0 5)-eq(MySubstring $nm 0 5) ){
$ret=MyRemove $nm -Force
}else{
$nmKeep = $nm
}
}else{
if($nm -notlike "*.log"){ $ret=MyRemove $nm -Force }
}
if([bool]$ret){
WriteLog $ret
if($ret -like "Exec*"){$cntExec++}
if($ret -like "Error"){$cntError++}
}
}
WriteLog "Finished Remove. Exec:$cntExec Error:$cntError .`r`n"
}
function DocsToPdfBK($pathBK){
$pathPdf = "$pathBK\Pdf"
if(-not(Test-Path $pathPdf)){
New-Item 'Pdf' -itemType Directory
}
DocsToPdfAtCurDir $pathPdf $pathBK
}