from a filename to file paths

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

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
Simon_Weel
Posts: 9
Joined: 2021-Dec-13, 3:53 pm

Re: from a filename to file paths

Post by Simon_Weel »

Code: Select all

dir newdoc2023.docx /s /b >result.txt
will do?
Lauraq
Posts: 3
Joined: 2023-May-15, 7:55 pm

Re: from a filename to file paths

Post 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
User avatar
Simon Sheppard
Posts: 127
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: from a filename to file paths

Post 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.
Post Reply