title: Convert CSV to txt file [powershell]
body: <p>I have a powershell script that edits a CSV and saves it. I then copy the CSV but save it as .txt</p>
  
  <p>I was told that a rename from filename.csv to filename.txt isn't the correct way ( in my opinion it works ) , but is there another way to save a CSV as a TXT file "properly"</p>
  
  <p>This is the current way I save the CSV as a .TXT</p>
  
  <pre><code>$csv = 'C:\Users\xxx\Desktop\xxx Playground\CSV Edit\20190522-Name-Num-Location-hey-hey.csv'
  $path = 'C:\Users\xxx\Desktop\xxx Playground\CSV Edit\'
  $pathdone = 'C:\Users\xxx\Desktop\xxx Playground\CSV Edit\done'
  
  $txtfile = $date + $lastname + "-" + $lastxxx + "-" + $lastnum + "-" + $lastxxxtwo + "-" + $lastloc + "-" + $newid + ".txt"
  
  # Save txt file as new format
  
  Copy-Item "$csv" -Destination "$path$txtfile"
  </code></pre>
  
  <p>Reminder, my method does work and outputs a .TXT , but is there a different way to "properly" do it without renaming the "copy-item and saving it as a txt"</p>
  
  <pre><code>$data = Import-Csv -Path $csv -Header 'Stuff','City','Number','InStock'    # or add whatever headers you like
  # get the first column as array of values
  $column1 = $data.Stuff
  # rotate the array values
  switch ($column1.Count) {
      1 { Write-Host "Nothing to do here. There is only one row of data.."; break}
      2 { 
          # swap the values
          $data[0].Stuff,$data[1].Stuff = $data[1].Stuff,$data[0].Stuff
          break
      }
      default {
          $newColumn1 = @($column1[-1]; $column1[0..($column1.Count -2)])
          # re-write the first column in the data
          for ($i = 0; $i -lt $newColumn1.Count; $i++) {
              $data[$i].Stuff = $newColumn1[$i]
          }
      }
  }
  </code></pre>