[英]Index was outside the bounds of the array error when processing .svd file
clear
# Powershell scripts used to mask Private Personal Information on data files.
# path to PERM file
$path = "MYURL\ABS.SVD"
# get file content
$content = Get-Content $path
$content | ForEach-Object {
$mask50 = 'X' * 50 # variables to makes fields by letter according to length
$mask30 = 'Y' * 30
$mask20 = 'A' * 20
$mask08 = 'Z' * 8
$mask05 = 'B' * 5
$mask16 = 'C' * 16
# if statement, if the string is at position 0-10, and begins with
# 'STARTDELIV' then run replace statement
if ($_.Substring(0,10) -eq 'STARTDELIV') {
$SplitString = $_.Split('|')
$SplitString[3] = $mask30 # Fields : To Fax Name
$SplitString[4] = $mask20 # Fields : To fax Number
$SplitString[9] = $mask50 # Fields : To EMail Address
$SplitString -join '|'
} else {
$_
}
} | Out-File "MYURL\ABS-Output.svd" -Encoding ASCII
I have a script which masked certain fields in a data file (fields seperated by '|'). 我有一个脚本,可屏蔽数据文件中的某些字段(用“ |”分隔的字段)。 I have done a lot of these and they work fine.
我已经做了很多这些工作,并且效果很好。 However, when I copy this exact file to another folder to use a different data file (.svd) I get the "Index was outside the bounds of the array", I've seen a few other threads on this but none really answer my query.
但是,当我将此精确文件复制到另一个文件夹以使用其他数据文件(.svd)时,出现“索引超出数组范围”的信息,我看到了其他一些线程,但没有一个能真正回答我的问题查询。
Curious as to why it still works in a particular folder location but not the other (I am changing the input and output urls to direct to the new folder). 好奇为什么它仍然可以在特定的文件夹位置而不是其他位置工作(我正在更改输入和输出URL以直接到新文件夹)。
Error below: 错误如下:
Index was outside the bounds of the array. AtMYURL-Masked-Fields.ps1:28 char:3 + $SplitString[3] = $mask30 #To Fax Name + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException + FullyQualifiedErrorId : System.IndexOutOfRangeException
Answer provided by @lit @lit提供的答案
"There is at least one record starting with STARTDELIV that does not have enough fields. find /I "STARTDELIV" "MYURL\\ABS.SVD" " “至少有一个以STARTDELIV开头的记录没有足够的字段。找到/ I“ STARTDELIV”“ MYURL \\ ABS.SVD”“
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.