China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-06 18:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » findstr text search View 2,611 Replies 21
Floor 16 Posted 2008-04-01 14:49 ·  中国 广东 深圳 罗湖区 电信
初级用户
★★
Credits 153
Posts 103
Joined 2008-03-27 19:38
18-year member
UID 114210
Gender Male
Status Offline
findstr /smic:"小龙女深情脉脉的看着杨过"

dir /s/b/a-d "笑傲江湖.txt"

Why doesn't it work? It's already in the current directory.
It seems that the findstr and dir commands are still missing a parameter, to be improved

[ Last edited by kioskboy on 2008-4-1 at 02:52 PM ]
Floor 17 Posted 2008-04-01 16:03 ·  中国 北京 华为云
银牌会员
★★★
Credits 1,436
Posts 739
Joined 2007-10-11 17:44
18-year member
UID 99469
Gender Male
Status Offline
```
@echo off
set "ph=D:\Program Files\Microsoft Office\Common Files\system\abc\色 酷全书"
pushd "%ph%"
findstr /smic:"小龙女深情脉脉的看着杨过" *.txt
popd
pause>nul

dir /s/b/a-d "笑傲江湖.txt"```
Floor 18 Posted 2008-04-01 16:32 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
This is my character search "command line tool" (really embarrassed to say)

There are any command usages that are not clear, just enter in the command prompt:

cmdstr shift

Change the path to your own as needed

@echo off
set "load=G:\cmd\Batch Processing Examples\bat files"
for /f "tokens=*" %%i in ('findstr /ms %1 "%load%\*.txt" ^|findstr .') do start /max /wait notepad "%%i"
goto :eof
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 19 Posted 2008-04-02 02:40 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 471
Posts 207
Joined 2007-05-03 14:53
19-year member
UID 87369
Gender Male
Status Offline
If you are not very clear about the usage of a certain command, enter in the command prompt:
cmdstr shift

What does it mean?
Floor 20 Posted 2008-04-02 11:36 ·  中国 广东 深圳 罗湖区 电信
初级用户
★★
Credits 153
Posts 103
Joined 2008-03-27 19:38
18-year member
UID 114210
Gender Male
Status Offline
### Solution:

To achieve displaying the absolute path when using `findstr` to search for the specified string in all `.txt` files, you can use the following command:

```batch
@echo off
set "ph=D:\Program Files\Microsoft Office\Common Files\system\abc\色 酷全书"
pushd "%ph%" & for /f "delims=" %a in ('dir /s/b/a-d *.txt') do @findstr /smic:"小龙女深情脉脉的看着杨过" "%a"
```

Explanation:
- `pushd "%ph%"` changes the current directory to the specified path.
- `for /f "delims=" %a in ('dir /s/b/a-d *.txt')` loops through all `.txt` files in the current directory and its subdirectories.
- `@findstr /smic:"小龙女深情脉脉的看着杨过" "%a"` searches for the specified string in each of the `.txt` files found, and the `%a` represents the full path of each `.txt` file, thus displaying the absolute path.

If you want to put it in a batch script (`.bat` file), the `%a` should be changed to `%%a`:

```batch
@echo off
set "ph=D:\Program Files\Microsoft Office\Common Files\system\abc\色 酷全书"
pushd "%ph%"
for /f "delims=" %%a in ('dir /s/b/a-d *.txt') do findstr /smic:"小龙女深情脉脉的看着杨过" "%%a"
```
Floor 21 Posted 2008-04-02 13:01 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Originally posted by ThinKing at 2008-4-2 02:40 AM:

What does it mean?


cmdstr is the batch file name, and shift is a command name I'm not very clear about; I'm just giving an example.
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 22 Posted 2008-04-02 13:03 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Originally posted by kioskboy at 2008-4-2 11:36 AM:


1 findstr /smic:"小龙女深情脉脉的看着杨过" *.txt
Display relative path (run in current directory)
2 dir /s/b/a-d "笑傲江湖.txt"
It would be nice if it could display the absolute path (...


Set the path yourself
@echo off
set "load=G:\cmd\Batch Example\bat files"
for /f "tokens=*" %%i in ('findstr /ms %1 "%load%\*.txt" ^|findstr .') do echo. Absolute path is: "%%i"
goto :eof
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Forum Jump: