@echo off & setlocal
cd Your_Folder
for %%j in (*.txt) do type "%%j" | find /I "computing.net" > nul || del "%%j"The above script by IVO will search for the word "computing.net" in the text files kept in the folder and delete it if the string is not present... What has to be modified to search in the directory?
You previously requested the same and here again my question (you never answered). What do you want to mean/achieve?
The posted script does what you requested for all files stored in a directory and strings/words are stored in files not in directories.
hi ivo the script deletes the text file in the folder where the batch file is kept..for eg consider D:\ if i put the script here it will delete the text files in the D:\ drive but its not entering the folders kept in the drive... thats what im trying to tell... sorry i didnt reply to your post ivo .. thanks...
Here the script I presume you wish (I presume since your request is not full clear to me).
At prompt type the batch name followed by the root folder for the directories structure you want to browse, e.g.
mybat D:
mybat F:\My DOC\My Letters:: MYBAT.BAT Usage: mybat Your Folder @echo off for /R "%*" %%i in (.) do ( for %%j in ("%%i.\*.txt") do type "%%j" | find /I "computing.net" >nul || del "%%j" )
Im getting an error msg "The full path of is too long." Clear scenario: In D drive there is a folder called check ..inside "check" folder there are 100's of folders containing text files ....When the batch is kept at the root for eg D:\Check and executed all text files should be deleted other than the files which have the word "computing.net"
Did you correctly type the batch command?
At prompt you need to type the batch name followed by the directory name otherwise you get the reported error message, e.g.
mybat D:\check
as reported on the first line of the script. Anyway use the following version that fixes a minor bug in the original one:: MYBAT.BAT Usage: mybat Your Folder @echo off & setlocal set mydir=%* if not defined mydir set mydir=%CD% for /R "%mydir%" %%i in (.) do ( for %%j in ("%%i\*.txt") do type "%%j" | find /I "computing.net" >nul || del "%%j" )
When located in the root of the structure you want to scan, you may omit to enter the directory
| « [Solved] Remove Leading zeros from... | [Solved] input to start a program ... » |