FolderDiff is a command line tool to compare contents of two folders.
####Features:
- Use simple or complex file selection criteria
- Combine file selectors
- Supports PowerShell and Windows Command Prompt
- Supports extremely long file- and foldernames up to 32.767 characters (Thanks Delimon.Win32.IO Library!)
- No recompilation required when search criteria changes
- Results can be presented / projected using PowerShell
- Fork the repository or download the zip.
- Extract the zip.
- Navigate to FolderDiffPowerShell folder
Usage: .\FolderDiff.ps1 referenceFolder differenceFolder [supportLongFilenames] ReferenceFolder: Full path of reference folder DifferenceFolder: Full path of difference folder [SupportLongFilenames]: optional boolean to enable long filenames support (default is $false)
Default file selection is to look for files:
- That are newer in the differenceFolder
- Or, files that only exists in the differenceFolder.
.\FolderDiff.ps1 C:\Backup\PC\Development\ C:\Backup\Laptop\Development\ | %{ $_.FullName }
or
.\FolderDiff.ps1 C:\Backup\PC\Development\ C:\Backup\Laptop\Development\ $true | %{ $_.FullName }
FolderDiff.bat C:\Backup\PC\Development\ C:\Backup\Laptop\Development\
Selecting files can be done by defining one or more file selectors. The proces of selecting files is done by evaluating all file selectors and take the distinct set of all results.
The signature of a file selector in PowerShell look this:
{ param($diffFile, $referenceFiles) $diffFile.File.Extension -eq '.txt' }
A file selector is basically a delegate that takes a differenceFile and all referenceFiles and returns a boolean to indicate if the differenceFile should be included in the results.
The default file selectors are defined in FolderDiffPowerShell\FolderDiff.ps1
in the function FolderDiff-Search
.
@($folderDiff.DiffFolder($referenceFolder, $differenceFolder, $supportLongFilesNames,
{ param($diffFile, $referenceFiles)
$refFile = (Get-File $referenceFolder $diffFile.RelativePath)
$diffFileIsNewer = $diffFile.File.LastWriteTime -gt $refFile.LastWriteTime
$refFile.Exists -and $diffFileIsNewer
},
{ param($diffFile, $referenceFiles)
-Not (File-Exists $referenceFolder $diffFile.RelativePath)
}
))
These file selectors could also be rewritten in a single file selector:
@($folderDiff.DiffFolder($referenceFolder, $differenceFolder, $supportLongFilesNames,
{ param($diffFile, $referenceFiles)
$refFile = (Get-File $referenceFolder $diffFile.RelativePath)
$diffFileIsNewer = $diffFile.File.LastWriteTime -gt $refFile.LastWriteTime
($refFile.Exists -and $diffFileIsNewer) -or (-not $refFile.Exists)
}
))
These conditions can be changed if necessary. Feel free to do so.
The files are expressed as a type MyFileInfo
which wraps FileInfoBase
together with the Relative path.
If we search in a folder c:\Backup\
and a file is found in c:\Backup\Pc\Folder\File.txt
then the RelativePath is Pc\Folder\File.txt
| Name | Name | Type | |---------------|------------------- |-------------------------------------------| | MyFile | MyFile.File | | | RelativePath | | string | | File | | System.IO.Abstractions.FileInfoBase | | | Attributes | System.IO.FileAttributes | | | CreationTime | datetime | | | CreationTimeUtc | datetime | | | Directory | System.IO.Abstractions.DirectoryInfoBase | | | DirectoryName | string | | | Exists | bool | | | Extension | string | | | FullName | string | | | IsReadOnly | bool | | | LastAccessTime | datetime | | | LastAccessTimeUtc | datetime | | | LastWriteTime | datetime | | | LastWriteTimeUtc | datetime | | | Length | long | | | Name | string |
Some cmdlets are available to help in selecting files
* [bool] File-Exists $path $relativePath * [MyFile] Get-File $path $relativePath
If we need to get the main folders which contain newer or unique files.
We can write: only list the folders which have 6 subdirectories or less.
.\FolderDiff.ps1 C:\Backup\PC\Development\ C:\Backup\Laptop\Development\ `
| %{ $_.Directory.FullName } | Get-Unique | ? { ($_.Split("\")).Length -lt 6 }
I will update the examples on request.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
20-12-2015 - Initial Readme.md
-
Delimon.Win32.IO by Johan Delimon
It is a great library to overcome the windows file system limitation on folder- and filename length.
-
System.IO.Abstractions by Tatham Oddie
Great and essential Nuget package if you want to write testable code which relies on the FileSystem.
I use this package for all my IO projects. Make sure to also checkout System.IO.Abstractions.TestingHelpers