Page 1 of 1

from a filename to file paths

Posted: 2023-May-15, 8:05 pm
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 :)

Re: from a filename to file paths

Posted: 2023-May-30, 11:03 pm
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.

Re: from a filename to file paths

Posted: 2023-Jun-05, 3:03 pm
by Lauraq
sorry, this is a .bat? Sorry I m not expert, tell me where I must put the string

Re: from a filename to file paths

Posted: 2023-Jun-05, 4:53 pm
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.

Re: from a filename to file paths

Posted: 2023-Jun-05, 6:53 pm
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"

Re: from a filename to file paths

Posted: 2023-Jun-05, 9:21 pm
by Simon Sheppard
See How-to: Run a PowerShell script
https://ss64.com/ps/syntax-run.html

Re: from a filename to file paths

Posted: 2023-Jun-07, 9:30 pm
by Lauraq
the script run but don't work