PowerShell: Compare two directories with slighly different naming conventions.
Quick Copy / Paste Answer
This works for a specific use case in which the two directories are
src
and
test\unit
, and in which the suffix to ignore is
.spec
.
(dir .\src\ | % { $_.BaseName } ) | compare (dir .\test\unit\ | % { $_.BaseName -replace ".spec", "" } )
Situation:
Two directories. One contains source files, the other contains test files.
./src/
client-model.ts
http-discovery-service.ts
id-token-model.ts
id-token-parser.ts
implicit-flow-service.ts
placeholder.ts
./test/unit
client-model.spec.ts
http-discovery-service.spec.ts
id-token-model.spec.ts
id-token-parser.spec.ts
implicit-flow-service.spec.ts
Approach:
Compare the base names of both directories, replacing the
".spec"
suffix in the test directory. Note: in PowerShell
>>
represents a new line of the same command.
PS (dir .\src\ | % { $_.BaseName } ) |
>> compare (dir .\test\unit\ |
>> % { $_.BaseName -replace ".spec", "" } )
Output:
The placeholder exists in one directory but not the other. Good.
InputObject SideIndicator
----------- -------------
placeholder =>