CSV: Add New, Update Existing

This topic contains 2 replies, has 2 voices, and was last updated by  Aaron Hardy 1 month ago.

  • Author
    Posts
  • #82568

    Aaron Hardy
    Participant

    I have a psobject that I need to compare against rows stored in a csv. The props are ImageName and File. File is unique, ImageName is not.

    If the current File object does not exist in a csv row, add the new row with File and ImageName.

    If the csv DOES contain a row that has the current File object, update the ImageName in that row only.

    Is this simple? Probably.

    Thanks for any suggestions.

  • #82571

    Clarence Holbrook
    Participant

    Aaron,

    What is the source of the new Imagename, and how do you correlate that to a specific filename (that may or maynot be in the CSV file?

    Thanks,
    Clarence

  • #82580

    Aaron Hardy
    Participant

    Clarence,

    The values in ImageName and File come from a an advanced function that generates the output as a psobject.

    A File (name) is associated with an ImageName; ImageName can be related to multiple File objects:

    ImageName   File
    ---------   ----
    ABCD.iso    A.jpg
    ABCD.iso    B.jpg
    ABCD.iso    C.jpg
    ABCD.iso    D.jpg
    EFG.iso     E.jpg
    EFG.iso     F.jpg
    EFG.iso     G.jpg
    

    I need to update a CSV with this info. If the File already exists in the CSV, update the ImageName associated with it (to avoid duplicates). Otherwise, just add the entire object to the CSV.

    I tend to overshoot so this could be a simple thing.

You must be logged in to reply to this topic.