我正在尝试解压缩文件夹并获取该文件夹中存在的文件数,并检查文件数= 32,否则发送一封带有当前文件名的电子邮件,并对当前文件执行infacmds,然后等待32个条件满足。
在此脚本中,我要检查文件数以及现有文件的列数,如果列数为-neq 280,则必须发送电子邮件错误。
列代码是这样的,我必须在主代码中引入它:
$columnCount = ( ( Get-Content "C:\Users\xs15169\Desktop\temp\OEC2_CFLOW.txt" | Select-Object -First 1 ) -Split ',' ).Count
echo "Column count is: $columnCount"
我尝试过的以下代码(#查找以下类型的文件格式.zip,它将解压缩文件并计数):
#unzip commands will be here
#LogWrite "Starting of process"
Function LogWrite
{
Param ([string]$logstring)
Add-content $log -value "$(Get-Date) $logstring"
}
try {
LogWrite "Start unzipping $zipfilename"
Remove-Item $unzipfolderdelete | Where { ! $_.PSIsContainer }
#Unzip $zipfilename $unzipfolder
Set-Alias sz "C:\Program Files\7-Zip\7z.exe"
sz x $zipfilename -o"$unzipfolder" -y
LogWrite "$zipfilename unzipped to $unzipfolder successfully"
$filecount= (dir $unzipfolder | measure).Count
if ($filecount -eq 32)
{
#LogWrite "File Count 32
#LogWrite "Executed informatica scripts for condition filecount equal to 32"
#LogWrite "End of if"
}
elseif ($filecount -ne 0)
{
LogWrite "File Count " + $filecount
$list = Get-ChildItem $unzipfolder
$incompletefilenames =""
ForEach($n in $list){
$incompletefilenames = $incompletefilenames + $n.Name + "<br>`n"
}
LogWrite $incompletefilenames
LogWrite "Sending email for filecount not equal to 32"
$Params = @{
email setup
}
Send-MailMessage @Params
LogWrite "Successfully emailed available file names"
#Execute Informatica scripts
LogWrite "Executed informatica scripts for condition filecount not equal to 32"
LogWrite "End of elseif"
}
else
{
LogWrite "File Count " + $filecount
$Params = @{
email setup
}
Send-MailMessage @Params
LogWrite "End of else"
}
}
答案 0 :(得分:0)
为此,您必须找出一些路径。
尝试一下:
Set-Alias sz "C:\Program Files\7-Zip\7z.exe"
$zipFile = "C:\temp\10 yard Fight.zip"
# Get Name of file without extension or path
$zipFolderToCreate = (gci $zipFile).BaseName
# Get path of zip
$path = (gci $zipFile).Directory.FullName
sz x -o"$path\*" "$zipFile" -r
$filecount= (dir "$path\$zipFolderToCreate" | measure).Count