from a filename to file paths

Microsoft Windows
Post Reply
Lauraq
Posts: 10
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:

newdoc2023.docx
document_34.docx
filedocument.docx

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
C:\Doc\archive\2021\save\filedocument.docx

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

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.
Lauraq
Posts: 10
Joined: 2023-May-15, 7:55 pm

Re: from a filename to file paths

Post by Lauraq »

sorry, this is a .bat? Sorry I m not expert, tell me where I must put the string
User avatar
Simon Sheppard
Posts: 153
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: from a filename to file paths

Post by Simon Sheppard »

PowerShell can be run from a .PS1 script or directly at the command line, just adjust the filenames to match what you have.
Lauraq
Posts: 10
Joined: 2023-May-15, 7:55 pm

Re: from a filename to file paths

Post by Lauraq »

I have create the.ps1 file but don't work. I see only the terminal interfare with a led

I have change it to:

CD E:\
$files = get-content list.txt
foreach ($file in $files) {dir $file -recurse | select -expandProperty fullname | out-file -append -encoding utf8 E:\result.txt}

The source is E:
The file with the list is named "list.txt"
User avatar
Simon Sheppard
Posts: 153
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: from a filename to file paths

Post by Simon Sheppard »

See How-to: Run a PowerShell script
https://ss64.com/ps/syntax-run.html
Lauraq
Posts: 10
Joined: 2023-May-15, 7:55 pm

Re: from a filename to file paths

Post by Lauraq »

the script run but don't work
Post Reply