from a filename to file paths

Microsoft Windows
Post Reply
Posts: 3
Joined: 2023-May-15, 7:55 pm

from a filename to file paths

Post by Lauraq »

Hi :)
I have a txt containing a list of document names (docx) For example:


I would need a script that searches the list of names inside a folder (and subfolders) and creates a txt containing the file path
For example:

C:\Doc\Nuova cartella\2023\newdoc2023.docx
C:\Doc\Nuova cartella\2020\base\doc\document_34.docx

Many thanks :)
User avatar
Simon Sheppard
Posts: 127
Joined: 2021-Jul-10, 7:46 pm

Re: from a filename to file paths

Post by Simon Sheppard »

Code: Select all

CD C:\Doc\
$files = get-content files.txt
foreach ($file in $files) {dir $file -recurse | select -expandProperty fullname | out-file -append -encoding utf8 C:\demo\result.txt}
This is assuming the current directory is the start point for the search.
Post Reply