Delete surplus entries inside dir text files

September 1, 2010 at 10:00:29
Specs: Windows XP
I thought I had solved the problems of a project I am working on but I have come up against an unexpected hitch. I have a directory of txt files each of which contain a number of file names (all listed on separate lines) which I have extracted from other txt files using vbscript. The file names have between 1 and 6 digits with .htm as the extension and should all be different and they are apart from unfortunate frequent inclusions of the actual file name also with .htm as the extension. The actual file name is sometimes included once and sometimes a number of times in the same file. I wish to remove any entries matching the file name. I know I should have written the vbscript properly so as to exclude the possibility of the file name being included but the how eludes me and, being a newbie, as I kind of struggled to get this far I would probably struggle in vain to fix this! I would rather just run a batch file which would then delete every line containing a file name matching entry.

Can anyone help with a bat file which will cycle through a directory of txt files and delete any line or lines in any of the files which matches the file name? eg if the file name was 123456.txt and the file contained a line or lines with the entry 123456.htm it/ they would be deleted.

I am able to delete such entries from a single file it's cycling through all the files in a directory that flummoxes me!

Any help would be appreciated!

Thank you

See More: Delete surplus entries inside dir text files

Report •

September 1, 2010 at 15:41:59
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
find /v /i "%%~Na.htm" < %%a > newfile
move /y newfile %%a

Helping others achieve escape felicity


Report •
Related Solutions

Ask Question