Solved Text files read in directory

February 9, 2012 at 09:01:41
Specs: Windows XP
@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?


See More: Text files read in directory

Report •

✔ Best Answer
February 11, 2012 at 03:32:53
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


#1
February 9, 2012 at 09:22:01
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.



Report •

#2
February 10, 2012 at 06:36:44
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...

Report •

#3
February 10, 2012 at 08:02:40
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"
)


Report •

Related Solutions

#4
February 11, 2012 at 00:23:29
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"


Report •

#5
February 11, 2012 at 03:32:53
✔ Best Answer
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

Report •

Ask Question