Simpatie.ro - matrimoniale
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
andrum94 pe Simpatie
Femeie
24 ani
Galati
cauta Barbat
27 - 80 ani
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[POWERSHELL] Find All Files Starting With Given Text

Pagini: 1 Moderat de TRaP, TonyTzu
pus acum 5 luni#1
Mrrrr
AdMiN
Postari: 2388
I have a bunch of books scanned in my PC and would like to check if I have any books from a given list of authors.

The following code will return the paths of the files if any.
F:\AUTHORS.txt contains a list of authors like Name, Surname - 1 per line.
F:\AUTHORS_RESULTS.txt will contain the results
D:\SCANS is the folder with several subfolders that's gonna be searched.

This runs in Terminal:

$authors = Get-Content "F:\AUTHORS.txt"
$output = "F:\AUTHORS_RESULTS.txt"
$folder = "D:\SCANS"

# Clear output file first
if (Test-Path $output) { Remove-Item $output }

foreach ($author in $authors) {
    Add-Content $output $author

    $files = Get-ChildItem $folder -Recurse -File -ErrorAction SilentlyContinue |
        Where-Object { $_.Name -like "*$author*" }

    foreach ($file in $files) {
        Add-Content $output $file.FullName
    }
}


_______________________________________


 
   
Pagini: 1  
Mergi la