Reputation: 1
I have a script that has been running for several years. In the past week, it has started throwing file-in-use-by-another process errors: Out-File : The process cannot access the file '\OB-UTIL-PRD-01\Client_Access_Zone\DIP\HO_NobleVR_DIP\nopipes.txt' because it is being used by another process.
Out-File : The process cannot access the file '\OB-UTIL-PRD-01\Client_Access_Zone\DIP\HO_NobleVR_DIP\index.txt' because it is being used by another process.
As near as I can tell from troubleshooting, my nopipes.txt
file is bumping into itself, so not all of the records are being added to the file, and my index.txt
is not getting anything added to it.
I tried removing the explicit New-Item
for each file, letting the Out-File
create the files, with same results. I also tried putting a pause in each iteration of the Out-File
to $nopipes
process, but again, I got the same results. Thank you for any help you can provide.
$ho_noble = '\\OB-UTIL-PRD-01\Client_Access_Zone\DIP\HO_NobleVR_DIP'
$nopipes = join-path -path $ho_noble -ChildPath "nopipes.txt"
$unlpath = join-path -path $ho_noble -ChildPath "*.unl"
$voxpath = join-path -path $ho_noble -ChildPath "*.vox"
$unlfilename = (Get-ChildItem -Path $unlpath -Name)
$voxsample = (Get-ChildItem -Path $voxpath -Name)
foreach ($line in $voxsample) {
$mystring = $line.substring(0, 8)
(Get-Content $unlpath) -notmatch $mystring | Out-File $unlpath
}
Remove-item $voxpath
$indexfile = Join-path -Path $ho_noble -ChildPath "index.txt"
#
# check the temp files from previous run have been deleted
# if not, delete them
#
if (test-path -Path $nopipes -PathType Leaf) {
Remove-item -Path $nopipes
}
#
if (Test-Path -Path $indexfile -PathType Leaf) {
Remove-item -Path $indexfile
}
#check the .unl file exists
if (-not (Test-Path -Path $unlpath -PathType Leaf)) {
throw 'no unl File'
}
else {
New-Item -path $nopipes -ItemType File
New-Item -path $indexfile -ItemType File
# get the .unl file and change the pipes to commas
$mydelimiter = '|'
$Sample = Get-Content -Path $unlpath
ForEach ($Line in $Sample) {
if ($Line.config_file -ne "") {
# remove any existing commas
$Line2 = $Line -replace ',', ''
forEach ($mydelimiter in $Line2) {
# now convert pipes to commas
$myline = $Line2 -replace '\|', ',' | Out-File -FilePath $nopipes -Append
# write-host $myline
}
}
}
#load the comma-separated version of the data into a records set and write to a new index.txt
$records = Import-Csv $nopipes
$incidents = $records | group file_num
for ($i = 0; $i -lt $incidents.Length; $i++) {
$mystring =
#wav file name
$incidents[$i].group[0].vox_file_name + ".wav" + "," +
#noble voice size, noble video size - we no longer get this metadata
"0" + "," + "0" + "," +
$incidents[$i].group[0].archive_status + "," +
# we no longer get noble screen recording metadata
'DISABLED' + "," +
#the agent id
$incidents[$i].group[0].tsr + "," +
$incidents[$i].group[0].rec_duration + "," +
#phone number has always been formatted nnn-nnnnnnn
$incidents[$i].group[0].areacode + "-" + $incidents[$i].group[0].phone + "," +
$incidents[$i].group[0].call_date + "," +
$incidents[$i].group[0].call_time + "," +
$incidents[$i].group[0].file_num + "," +
#the noble list id
$incidents[$i].group[0].listid + "," +
#we no longer get agent name in metadata
"" + "," +
#the campaign
$incidents[$i].group[0].appl + "," +
$incidents[$i].group[0].d_record_id + "," +
$incidents[$i].group[0].d_device_id + "," +
$incidents[$i].group[0].station + "," +
$incidents[$i].group[0].filler1 + "," +
#loan num
$incidents[$i].group[0].filler2 + "," +
$incidents[$i].group[0].filler3 + "," +
$incidents[$i].group[0].filler4
Out-File -FilePath $indexfile -Append -Encoding unicode -InputObject $mystring
}
#tidy up
Remove-Item -Path $unlpath
Remove-item -Path $nopipes
}
Upvotes: 0
Views: 179