Dear wise Stackoverflow Community
Is it possible with powershell, to get all filenames in a directory and search for them each in another directory?
Something like:
Path A (C:\Temp):
C:\Temp\Test2\Test.docx
C:\Temp\Test\test.txt
C:\Temp\Test\file.html`
and search for each file (Test.docx,test.txt,file.html) in a different path e.g. C:\Filesnew ?
and in the best case, the export to csv would be something like:
| Filename | Filepath | Found? | FoundIn |
| -------- | ------------------------ |--------| ----------------------------------------|
| Test.docx | C:\Temp\Test2\Test.docx | y | C:\Filesnew\TransferedFiles\Test.docx |
| test.txt | C:\Temp\Test\test.txt | n | |
| file.html | C:\Temp\Test\file.html | y | C:\Filesnew\webfiles\file.html |
I'm currently stuck at this code:
$files = gci -r * | select-object name, fullname
foreach ($file in $files)
{
gci -path C:\Filesnew -recurse | where {$_.Name -match $file.Name} | select-object $files.Name $files.fullname, $file.fullname | Export-CSV C:\test.csv
}
Can you help me out?