[Solved] Text files read in directory

Score
0
Vote Up
February 9, 2012 at 09:01:41 Pacific
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?


Jump to Best Answer ↓   Report •


#1
Vote Down
Score
1
Vote Up
February 9, 2012 at 09:22:01 Pacific

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.



Reply ↓  Report •

#2
Vote Down
Score
-1
Vote Up
February 10, 2012 at 06:36:44 Pacific

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...

Reply ↓  Report •

#3
Vote Down
Score
1
Vote Up
February 10, 2012 at 08:02:40 Pacific

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"
)


Reply ↓  Report •

#4
Vote Down
Score
0
Vote Up
February 11, 2012 at 00:23:29 Pacific

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"


Reply ↓  Report •

Related Posts

#5
Vote Down
Score
0
Vote Up
February 11, 2012 at 03:32:53 Pacific

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

Reply ↓  Report •

Reply to Message Icon Start New Discussion
« [Solved] Remove Leading zeros from... [Solved] input to start a program ... »