I'm trying to get this code to print to a file and it wont, can anyone help? It's a powershell script.
$itemsofCars =@()
$cars = @()
$typefile = Get-Content "C:\Newfolder\cars_not_formatted.txt"
foreach ($line in $typefile)
{
if($Matches.Count -gt 1)
{
$thisItem = $Matches[1]
$Matches.Clear()
if(
$thisItem.Contains("_Wheel") -or
$thisItem.Contains("_Doors_") -or
$thisItem.Contains("_trunk_") -or
$thisItem.Contains("_hood_") -or
$thisItem.Contains("_coDriver_") -or
$thisItem.Contains("_driver")
)
{
$itemsofCars += $thisItem
}
else
{
$cars += $thisItem
}
}
}
#$itemsofCars
#$cars
foreach ($car in $cars)
{
$car | Out-file 'C:\Newfolder\test.txt'
}
I'm trying to take the data from one file then separate it to then save it to another file. There is more that will be doing but this is my first step.
Edit:
My end goal is to make this script take the list of types from the list a mod creator made to list the vehicles in his dayz mod, and add the proper cfg code to it. This way I don’t have to go through all 50+ vehicles on the list and add their respective part so they can spawn fully. For some reason the creator didn’t supply this file.
This will be the end result of the script:
<type name="Audi_RS6">
<attachments chance="1">
<item name="Audi_RS6_Doors_cargo1"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Wheel"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Wheel"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Wheel"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Wheel"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Wheel"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Doors_cargo2"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Doors_coDriver"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Doors_Driver"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="Audi_RS6_Doors_Hood"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="SparkPlug"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="CarBattery"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="CarRadiator"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="HeadlightH7"
chance="1"/>
</attachments>
<attachments chance="1">
<item name="HeadlightH7"
chance="1"/>
</attachments>
</type>
for right now I'm testing for it to print to a file. I'll move on to the rest after.