Page 1 of 2
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.
Re: from a filename to file paths
Posted: 2023-Jun-05, 2:57 pm
by Lauraq
thanks but i run the bat and nothing happens
Re: from a filename to file paths
Posted: 2023-Jun-05, 4:54 pm
by Simon Sheppard
You may have to adjust the filenames to match what you have.
Re: from a filename to file paths
Posted: 2023-Jun-05, 6:57 pm
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
Re: from a filename to file paths
Posted: 2023-Jun-07, 2:51 pm
by Simon_Weel
You have to edit 'typefiles.txt' to include all file names to scan for, like
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
Re: from a filename to file paths
Posted: 2023-Jun-07, 9:29 pm
by Lauraq
dont work for me
Re: from a filename to file paths
Posted: 2023-Jun-08, 9:30 am
by Simon_Weel
What happens when you run the script?
Can you post the script and the content of 'typefiles.txt'?