Reputation: 15
I am trying to make a text file filter which filters a particular word from the text using a Windows batch-file.
My code:
findstr ".txt" filename.txt > name.txt
filename.txt:
C:\Users\PhilipRamya\Desktop\fruits.txt
Expected output in name.txt
fruits.txt
Actual output in name.txt
C:\Users\PhilipRamya\Desktop\fruits.txt
Upvotes: 0
Views: 481
Reputation: 49216
I don't see any reason to use findstr.exe
or find.exe
in directory %SystemRoot%\System32
in this case to first filter the list of full qualified file names in list file filename.txt
before processing the filtered file names further with command FOR. It is better in my point of view to directly process the list file with FOR.
@echo off
(for /F "usebackq eol=| delims=" %%I in ("filename.txt") do if /I "%%~xI" == ".txt" echo %%~nxI)>name.txt
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
for /?
if /?
Upvotes: 1