PowerShell小僧:ファイル名の一括置換(改21) [コンピューター]
PowerShell小僧:ファイル名の一括置換(改20)
https://cheese999.blog.ss-blog.jp/2021-10-29
に最近した変更。
1.フォルダにファイルが存在しない時、置換処理を実行しない
# ファイルがあるフォルダへ移動
Set-Location -LiteralPath $MyFilePath1
$NumFile1 = (Get-ChildItem|Measure-Object).Count
if($NumFile1 -eq 0){
Write-Host "フォルダ("$MyFilePath1")にファイルが存在しません。"
$ErrFlg1 = $TRUE
}else{
(以下、略)
2.ファイル名を一括置換した後、Zip圧縮する、しないを選択できるようにした。
if($MyFlag1 -eq 0){
$FlgCompZip1 = Read-HostDefault "Zip圧縮しますか? (しない/する=0/1)" $FlgCompZip1
}
# Zip圧縮
if($FlgCompZip1 -eq 1){
$myFilePath2 = Convert-Path ".." # 1つ上のフォルダの絶対パス
$NewFileName3 = $NewFileName1.Replace("_","") # 新しいファイル名から_を取る
$NewFileName3 = $NewFileName3 + ".zip" # 拡張子zipをつける
$myFilePath2 = $myFilePath2 + "\" + $NewFileName3
myFCompZip2 -InFolderName1 $MyFilePath1 -OutZipName1 $myFilePath2 -ScriptPath1 $ScriptPath1
if($MyFlag1 -eq 0){Read-HostDefault "OK?" > $null} # 入力待ち
}else{
Write-Host "Zip圧縮しません。"
}
【参考】
【PowerShell】ディレクトリ、ファイル調査
https://qiita.com/MakotoIshikawa/items/96827becc4c3e5e68a56
https://cheese999.blog.ss-blog.jp/2021-10-29
に最近した変更。
1.フォルダにファイルが存在しない時、置換処理を実行しない
# ファイルがあるフォルダへ移動
Set-Location -LiteralPath $MyFilePath1
$NumFile1 = (Get-ChildItem|Measure-Object).Count
if($NumFile1 -eq 0){
Write-Host "フォルダ("$MyFilePath1")にファイルが存在しません。"
$ErrFlg1 = $TRUE
}else{
(以下、略)
2.ファイル名を一括置換した後、Zip圧縮する、しないを選択できるようにした。
if($MyFlag1 -eq 0){
$FlgCompZip1 = Read-HostDefault "Zip圧縮しますか? (しない/する=0/1)" $FlgCompZip1
}
# Zip圧縮
if($FlgCompZip1 -eq 1){
$myFilePath2 = Convert-Path ".." # 1つ上のフォルダの絶対パス
$NewFileName3 = $NewFileName1.Replace("_","") # 新しいファイル名から_を取る
$NewFileName3 = $NewFileName3 + ".zip" # 拡張子zipをつける
$myFilePath2 = $myFilePath2 + "\" + $NewFileName3
myFCompZip2 -InFolderName1 $MyFilePath1 -OutZipName1 $myFilePath2 -ScriptPath1 $ScriptPath1
if($MyFlag1 -eq 0){Read-HostDefault "OK?" > $null} # 入力待ち
}else{
Write-Host "Zip圧縮しません。"
}
【参考】
【PowerShell】ディレクトリ、ファイル調査
https://qiita.com/MakotoIshikawa/items/96827becc4c3e5e68a56
タグ:powershell
ヤバイぜ! ありがとうございます(^_0)ノ
by cheese999 (2021-12-11 04:34)