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-08-07 05:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help me take a look at this batch file View 611 Replies 2
Original Poster Posted 2008-01-06 20:09 ·  中国 河南 洛阳 栾川县 联通
新手上路
Credits 11
Posts 4
Joined 2007-05-02 18:13
19-year member
UID 87289
Gender Male
Status Offline
@echo off
set /p x=Please enter the filename, pay attention to case:
for %%i in (C D E F ) do (
for /f %%a in ('dir %%i:\ /s/b^|find "%x%"') do (
set b=%%~ftza
)
)
for /f "tokens=1-4" %%a in ("%b%") do (
set f=%%a
set g=%%b
set e=%%c
set h=%%d
)
echo The file has been found!
echo File size is %e%KB
echo File modification time is %f% %g%
echo File path is %h%%x%
pause>nul



I wrote this myself. It's rather cumbersome, so I hope you experts will go easy on me. Right now there is one problem: when the path of the file you're searching for contains Chinese characters or spaces, it errors out... Can anyone help me solve this?
Floor 2 Posted 2008-01-06 20:21 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
第一高手 第二高手

Floor 3 Posted 2008-01-07 02:42 ·  中国 浙江 杭州 电信
高级用户
★★
Credits 537
Posts 219
Joined 2007-08-04 09:43
19-year member
UID 94620
Gender Male
From 杭州--半山
Status Offline
@echo off
color 3f
cls
:1

title File Search Tool by-junchen2 date-2007-09-28
@echo n filename, wildcards can be used.
@echo e file extension
@echo p drive letter
@echo o open mode: use s to open the found file, use a to open the folder containing the file

del /q E:\findfile
set /p var=n/e/p/o
for /f "tokens=1-4 delims=/" %%a in ("%var%") do call :f "%%a" "%%b" "%%~sc" %%d

:f

if "%~1"=="" echo Missing parameter, please enter it again & goto :1
if "%~2"=="" echo Missing parameter, please enter it again & goto :1
if "%~3"=="" echo Missing parameter, please enter it again & goto :1
if "%~4"=="" echo Missing parameter, please enter it again & goto :1

cd\
cd /d %3

dir /b /s /a %~1.%~2>> e:\findfile\list.txt
if errorlevel 1 goto :n
for /f "delims=" %%d in (e:\findfile\list.txt) do echo %%~sd >>e:\findfile\s_list.txt

@for /f "delims=" %%e in (e:\findfile\s_list.txt) do echo %%~dpe>>e:\findfile\sp_list.txt

type e:\findfile\list.txt|findstr /n ".*" >>e:\findfile\n_list.txt
type e:\findfile\s_list.txt|findstr /n ".*" >>e:\findfile\sn_list.txt
type e:\findfile\sp_list.txt|findstr /n ".*" >>e:\findfile\spn_list.txt
::-----------^^^Add line numbers to the long/short filename lists and output to n_list.txt, sn_list.txt

cls
echo.
echo %~1/%~2/%~3/%4
echo.
findstr /a:a /n ".*" e:\findfile\list.txt

:c
set /p nub= Enter the line number to search:

if %4 equ a goto :a
if %4 equ s goto :s
:a
@for /f "tokens=1-3 delims=:" %%a in ('type e:\findfile\sn_list.txt') do echo %%a|findstr "\<%nub%" &&start %%b:%%c && goto :2
:s
@for /f "tokens=1-3 delims=:" %%a in ('type e:\findfile\spn_list.txt') do echo %%a|findstr "\<%nub%" &&start %%b:%%c
:2
set /p c=ind_other input=y
if "%c%"=="y" echo. & goto :1
goto :c
Forum Jump: