Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9084689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:03:28+00:00 2026-06-16T21:03:28+00:00

Given the following sample code (Powershell), which is based on this solution : $newFiles

  • 0

Given the following sample code (Powershell), which is based on this solution:

$newFiles = @(Get-ChildItem -recurse -path "c:\path1");
$oldFiles = @(Get-ChildItem -recurse -path "c:\path2");
Compare-Object -ReferenceObject $newFiles -DifferenceObject $oldFiles -Property FullName,Length,LastWriteTime

I have SideIndicator to tell whether or not an object with the same property set is present in either sides. But this is usually of little use for production purposes. What I really need is key all objects by FullName and then compare by Length and LastWriteTime (for the above example). If different, be able to tell what exactly is different (Length or LastWriteTime or both), and how exactly (>, <, =). Is it possible with Powershell, using built-in ways?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:03:29+00:00Added an answer on June 16, 2026 at 9:03 pm

    Compare-Object is a pretty feature-light cmdlet. It could stand some serious improvements. The best way I could get this to work was to piece out the removed/added files into a separate bucket and then compare just the same files using Name not FullName with a SyncWindow of 1 e.g.:

    $removed = Compare-Object -ReferenceObject $oldFiles -DifferenceObject $newFiles -Property Name -PassThru | Where {$_.SideIndicator -eq '<='}
    $added = Compare-Object -ReferenceObject $oldFiles -DifferenceObject $newFiles -Property Name -PassThru | Where {$_.SideIndicator -eq '=>'}
    $removedNames = $removed | Foreach {$_.Fullname}
    $same = $oldFiles | Where {$_.Fullname -notin $removedNames}
    Compare-Object -ReferenceObject $same -DifferenceObject $newFiles -Property Name,Length,LastWriteTime -SyncWindow 1
    

    This gave me results like this:

    Name                                                 Length LastWriteTime                 SideIndicator
    ----                                                 ------ -------------                 -------------
    AssemblyInfo.Shared.cs                                  340 8/28/2012 1:21:53 AM          =>
    AssemblyInfo.Shared.cs                                  340 8/28/2012 1:21:28 AM          <=
    EchoArgs.cs                                             825 8/28/2012 1:21:54 AM          =>
    EchoArgs.cs                                             825 8/28/2012 1:21:30 AM          <=
    AssemblyInfo.cs                                         151 8/28/2012 1:21:54 AM          =>
    AssemblyInfo.cs                                         151 8/28/2012 1:21:31 AM          <=
    

    Even so, part way through the listing the files get out of sync. Go figure. If you eliminate the SyncWindow parameter, you still get “correct” results it is just that the files are scattered about and not lined up one under another. 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this following sample code which clones a table row, sets some properties and
Given the following code sample: uint8_t i, in, ni; i = in = 2;
Given the following sample form code and CSS stylesheet Form <div class="Center_300 "> <button
Given the following MSDN sample code, why can't I define the Action delegate inline:
In the university we were given the following code sample and we were being
Given the following code: LinkedList list = mock(LinkedList.class); doCallRealMethod().when(list).clear(); list.clear(); by executing this test,
Given the following sample code: $(document).ready(function(){ $(:input).blur(function(){ alert(The input type is: ); //How would
Given the following code sample: public class WeirdStuff { public static int doSomething() {
Given the following sample code; class Program { static void Main(string[] args) { var
Given the following code: namespace sample { class a { } class b :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.