中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-11-11 17:33
47,815 topics / 349,930 posts / today 0 new / 48,291 members
DOS批处理 & 脚本技术(批处理室) » findstr text search
Printable Version  3,360 / 21
Floor16 kioskboy Posted 2008-04-01 14:49
初级用户 Posts 103 Credits 153
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 ]
Floor17 abcd Posted 2008-04-01 16:03
银牌会员 Posts 739 Credits 1,436
```
@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"```
Floor18 plp626 Posted 2008-04-01 16:32
银牌会员 Posts 1,020 Credits 2,278
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

Floor19 ThinKing Posted 2008-04-02 02:40
中级用户 Posts 207 Credits 471
If you are not very clear about the usage of a certain command, enter in the command prompt:
cmdstr shift

What does it mean?
Floor20 kioskboy Posted 2008-04-02 11:36
初级用户 Posts 103 Credits 153
### 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"
```
Floor21 plp626 Posted 2008-04-02 13:01
银牌会员 Posts 1,020 Credits 2,278
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.
Floor22 plp626 Posted 2008-04-02 13:03
银牌会员 Posts 1,020 Credits 2,278
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
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023