Hi
I'm able to get the filepaths of all the files existing in a folder and all its subfolders.
However I need to get the filepaths of only specific files.
I have a folder which contains 300 subfolders and total number of files is 12332
i need to get the filepaths of only a 1000 files.
For example:
====================================
Input:
one.txt
two.txt
three.txt
.
.
.
.
.
.
thousand.txt
==========================================
output
C:\Users\ladduq\Desktop\New folder\okay\one.txt
C:\Users\ladduq\Desktop\New folder\okay\two\two.txt
C:\Users\ladduq\Desktop\New folder\three.txt
.
.
.
.
C:\Users\ladduq\Desktop\thousand.txt
===========================================
How can i acheive this.please suggest
Regards
Ladduq
Display filepaths of specific files
Moderator: DosItHelp
Re: Display filepaths of specific files
Are the filenames unique amongst the 12,000 files?
If so then run this in the root of the folder tree and with the filelist.txt in the same folder.
If so then run this in the root of the folder tree and with the filelist.txt in the same folder.
Code: Select all
@echo off
dir /b /s /a-d >"%temp%\temp.list"
for /f "delims=" %%a in (filelist.txt) do (
find /i "\%%a" <"%temp%\temp.list" >>"filelist2.txt"
)
del "%temp%\temp.list"
Re: Display filepaths of specific files
@foxidrive - almost, but a few problems:
test.txt will match "c:\folder\test.txt.bak" and "c:\test.txt\somethingelse"
Can be fixed by switching to FINDSTR with /I /E and /C:"\%%a" options
Here is a similar but more efficient solution:
Create a text file containing the file names you want to find, one file per line. Prefix each file name with a backslash \
Then simply run the following command (no need for a batch file, but it certainly works in one)
If you alrady have a text file of file names without the backslash prefix, you can use the following to add the prefix:
Change %F to %%F if you put the code in a batch file.
Another way to do this without FINDSTR. Assume you have a list of file names (no prefix) in a file named NOPREFIX.TXT
Again, change %F to %%F if using a batch file
Dave Benham
test.txt will match "c:\folder\test.txt.bak" and "c:\test.txt\somethingelse"
Can be fixed by switching to FINDSTR with /I /E and /C:"\%%a" options
Here is a similar but more efficient solution:
Create a text file containing the file names you want to find, one file per line. Prefix each file name with a backslash \
Code: Select all
\one.txt
\two.txt
etc.
Then simply run the following command (no need for a batch file, but it certainly works in one)
Code: Select all
dir /b /a-d /s "C:\Users\ladduq\Desktop\New folder\*" | findstr /lie /f:files.txt >output.txt
If you alrady have a text file of file names without the backslash prefix, you can use the following to add the prefix:
Code: Select all
>files.txt (for /f "eol=: delims=" %F in (noprefix.txt) do @echo \%F)
Change %F to %%F if you put the code in a batch file.
Another way to do this without FINDSTR. Assume you have a list of file names (no prefix) in a file named NOPREFIX.TXT
Code: Select all
>output.txt (for /f "eol=: delims=" %F in (noprefix.txt) do @dir /b /a-d /s "C:\Users\ladduq\Desktop\New folder\%F")
Again, change %F to %%F if using a batch file
Dave Benham
Re: Display filepaths of specific files
@foxidrive and @Dave Benham Thank You for The Support
Actually each file has a single line starting with the word "start"
so can i also get the file paths along with the line which starts with the word "start"
For example:
====================================
Input:
one.txt(if one.txt file contains a start line like "Start this promo first")
two.txt(if two.txt file contains a start line like "Start this promo should be ended at last")
three.txt
.
.
.
.
.
.
thousand.txt
==========================================
output:
path
C:\Users\ladduq\Desktop\New folder\okay\one.txt
Start
Start this promo first
path
C:\Users\ladduq\Desktop\New folder\okay\two\two.txt
start
Start this promo should be ended at last
etc.
can we acheive this with file names please suggest.
Thanks & Regards
Ladduq
Actually each file has a single line starting with the word "start"
so can i also get the file paths along with the line which starts with the word "start"
For example:
====================================
Input:
one.txt(if one.txt file contains a start line like "Start this promo first")
two.txt(if two.txt file contains a start line like "Start this promo should be ended at last")
three.txt
.
.
.
.
.
.
thousand.txt
==========================================
output:
path
C:\Users\ladduq\Desktop\New folder\okay\one.txt
Start
Start this promo first
path
C:\Users\ladduq\Desktop\New folder\okay\two\two.txt
start
Start this promo should be ended at last
etc.
can we acheive this with file names please suggest.
Thanks & Regards
Ladduq
Re: Display filepaths of specific files
Well that is a completely different question.
This simple one liner:
Gives output like the following:
To get output as you have described, you just need to parse the results in a FOR /F loop:
If you only provide a relative path without the drive letter, then you need:
This simple one liner:
Code: Select all
findstr /si "^start\>" "C:\Users\ladduq\Desktop\New folder\*"
Gives output like the following:
Code: Select all
C:\Users\ladduq\Desktop\New folder\okay\one.txt:Start this promo first
C:\Users\ladduq\Desktop\New folder\okay\two\two.txt:Start this promo should be ended at last
To get output as you have described, you just need to parse the results in a FOR /F loop:
Code: Select all
@echo off
for /f "tokens=1,2* delims=:" %%A in ('findstr /si "^start\>" "C:\Users\ladduq\Desktop\New folder\*"') do (
echo Path
echo %%A:%%B
echo Start
echo %%C
echo(
)
If you only provide a relative path without the drive letter, then you need:
Code: Select all
@echo off
for /f "tokens=1* delims=:" %%A in ('findstr /si "^start\>" "New folder\*"') do (
echo Path
echo %%~fA
echo Start
echo %%B
echo(
)