Page 1 of 1

from a filename to file paths

Posted: 2023-May-19, 7:07 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 :)

P.S. I apologize for posting this (I assume) in the wrong section

Re: from a filename to file paths

Posted: 2023-May-23, 8:08 am
by Simon_Weel

Code: Select all

dir newdoc2023.docx /s /b >result.txt
will do?

Re: from a filename to file paths

Posted: 2023-May-25, 8:17 pm
by Lauraq
thanks but can you tell me exatly where I must put the string?
I m looking for a .bat that execute the operation

And, the filename list is in txt format

Re: from a filename to file paths

Posted: 2023-May-30, 10:51 pm
by Simon Sheppard
If you just have a small number of files, you can do what Simon_Weel suggests and hard code the filenames:

dir newdoc2023.docx /s /b >result.txt
dir document_34.docx /s /b >>result.txt
etc

If you have a lot of files then you will want to automate reading the filenames in a loop:

Code: Select all

@echo off
for /f %%G in ('type files.txt') do call :sub "%%G"
goto:eof

:sub
dir %1 /s /b >>result.txt
Thats assuming the current directory is the top of the tree to be searched.