Export Import Compare 2 CSV files RRS feed

  • General discussion

  • I have 2 csv files that list files with their full paths and trying to compare them and export only files that don't match. What I need to do to get a more accurate export is remove part of the path.

    change C:\Users\username\Documents\Snagit\snagit.exe



    to just Documents\Snagit\snagit.exe

    Here's my code:

    $Win7 = ($Desktop + "Windows7.csv")
    $Win10 = ($Desktop + "Windows10.csv")
    $Win7data = Import-csv $Win7
    $Win10data = Import-csv $Win10
    Compare-Object $Win7data $Win10data | Select InputObject | Export-csv ($Desktop + "MissingFiles.csv") -NoTypeInformation

    Jason Ostrowski

    Friday, August 10, 2018 2:46 PM

All replies

  • You need to control that by how you make your CSV files.

    Just list the files names in the target and not the full name.

    $rootfolder = 'f:\username'
    Get-ChildItem $rootfolder |
         Select @{n='Filename';e={$_.FullName -replace $rootfolder } |
         Export-Csv ...


    Friday, August 10, 2018 2:59 PM
  • Part of the issue is that this will be part of a larger script... So, the username will vary so I am trying to remove

    C:\Users\username\Documents\Snagit\snagit.exe as


    So I am trying to incorporate that variable into the export:

    (dir $SourceList -Recurse -Exclude $ExclusionList).FullName  | split-file-replace $home | Out-File ($Desktop + "Windows7.csv")

    Jason Ostrowski

    Friday, August 10, 2018 4:00 PM
  • Your code is not real code.  Your issue is too vague.


    Friday, August 10, 2018 4:03 PM
  • Your question does not make any sense.

    Start very slow - Post a very short example script that contains only the absolute minimum amount of code needed to reproduce the problem. If you have input files: Post an example, but only the minimum amount of data needed to illustrate the problem. In short, you need to follow the sscce principle.

    There are multiple reasons for this approach:

    1. Writing short sample code helps to ensure that you understand the code that you are writing. It simply won't do to try to paste stuff together and expect it to magically work.
    2. When you whittle the problem down to its bare necessity, it helps you to actually understand the problem you are experiencing, and in so doing, this will usually help you answer your own question. If it doesn't answer it, you will at least have a specific question you can ask.
    3. Of necessity, it's simply not possible to answer vague questions in a forum. Your question needs to be focused and very specific.


    The following links should help explain more about how to ask good questions:


    -- Bill Stewart [Bill_Stewart]

    Friday, August 10, 2018 4:33 PM
  • I guess an easier way to address what I am trying to do in my script is... After copying a folder and all it's contents from 1 location to another, how do I compare the data to make sure all data was copied and if any wasn't; list the missing data in a .csv. 

    That's what I am trying to accomplish... I did it with exporting what I was going to copy to a csv and then exporting what was copied to another csv and compare the 2 for discrepancies 

    Jason Ostrowski

    Friday, August 10, 2018 5:47 PM
  • If the copy completed without error then you have no missing files.  The NT file system is transacted.  When a file is copied the system validates the transaction for you. If the file failed to copy correctly then an error will be returned for that file. Just catch the errors.

    This is where RoboCopy excels. RC uses the file system and copies at high speed.  RC also creates a detailed and validated log file.

    Since old Windows 98 there has not been a need to do what you are trying to do.


    Friday, August 10, 2018 5:57 PM
  • It's weird but no errors are reported but a folder and the 2 files within the folder didn't copy over and I validated that. So, now I wonder what else is not being copied over and doing the pre-post csv export did show some discrepancies but the csv is displaying oddly... Example:

    @{C:\Users\username\Documents\Add-in Express=C:\Users\username\Downloads\kix2010.doc}

    The Add-in Express folder and it's contents are missing but C:\Users\username\Downloads\kix2010.doc is NOT missing so... strange... 

    This is how I am copying the data over:

    Get-ChildItem -Path $Downloads | % { Copy-Item $_.fullname ($USBdrive + $user + "\" + "Downloads") -Recurse -Force -Exclude $ExclusionList }

    Jason Ostrowski

    Friday, August 10, 2018 6:12 PM
  • As jrv pointed out, why reinvent the wheel when we have robocopy? Why are you trying to script this?

    You are asking vague questions and hoping someone will figure out what you mean.

    Please refer to my earlier comments. Read and learn how to ask a good technical question.

    -- Bill Stewart [Bill_Stewart]

    Friday, August 10, 2018 6:27 PM
  • The code is just wrong.

    Get-ChildItem $Downloads -Force -Exclude $ExclusionList| 
        Copy-Item -Target "$USBdrive$user\Downloads"

    RoboCopy will prevent you from having to understand how PowerShell and Net work with the file system.

    Robocopy  c:\users\username\downloads "$USBdrive$user\Downloads" /X /XF $exlusions /E /V /LOG:logfile.txt

    There are many other switches  to customize the copy and ways to increase performance.


    robocopy /? | Out-GridView


    • Edited by jrv Friday, August 10, 2018 7:19 PM
    Friday, August 10, 2018 7:19 PM