from a filename to file paths

Microsoft Windows
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 :)

P.S. I apologize for posting this (I assume) in the wrong section
Simon_Weel
Posts: 33
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: 10
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: 187
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.
Lauraq
Posts: 10
Joined: 2023-May-15, 7:55 pm

Re: from a filename to file paths

Post by Lauraq »

thanks but i run the bat and nothing happens
User avatar
Simon Sheppard
Posts: 187
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: from a filename to file paths

Post by Simon Sheppard »

You may have to 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 think is correct. The file is named "typefiles.txt"
I have put the file and the bat in E: that is the source folder

And I have edit the script to

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

:sub
dir %1 /s /b >>result.txt
Simon_Weel
Posts: 33
Joined: 2021-Dec-13, 3:53 pm

Re: from a filename to file paths

Post by Simon_Weel »

You have to edit 'typefiles.txt' to include all file names to scan for, like

Code: Select all

newdoc2023.docx
document_34.docx
etc.
If you want to scan for all .docx files, you can use something like

Code: Select all

dir c:\doc\*.docx /s /b >result.txt
Lauraq
Posts: 10
Joined: 2023-May-15, 7:55 pm

Re: from a filename to file paths

Post by Lauraq »

dont work for me :(
Simon_Weel
Posts: 33
Joined: 2021-Dec-13, 3:53 pm

Re: from a filename to file paths

Post by Simon_Weel »

What happens when you run the script?
Can you post the script and the content of 'typefiles.txt'?
Post Reply