|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『楼 主』:
查找文件并操作(查看路径、复制、删除).bat (9.5更新)
使用 LLM 解释/回答一下
*.bat
现在还有一个问题,源自
for /f "tokens=* delims= " %%a in (%dati%_9.txt) do (find %dati%_6.txt /v /i "%%a">>%dati%_5.txt)
这句,我存过滤的那文件有几行生成的查找文件就有几重复,这个怎么弄掉?
现在就想把恢复删除再重新弄下,搞的自动化点
@echo off
:: 8-31 增加记录日志功能
:: 9-1 增加全盘搜索、完全匹配查找功能
:: 9-2 增加多文件搜索,可自定义添加过滤路径
:: 9-3 增加了搜索文件名时检测“路径中含有搜索的文件名字符串而文件名中没有”就删除掉这个路径
增加了搜索文件名时检测“路径中含有搜索的文件名字符串”就删除掉这个路径,这只是个路径
:: 9-4 增加了搜索文件名过滤,不让用户搜索完全匹配的"windows","system32"等,用户可手动添加删除
:: 各临时文件说明
:: %dati%_9.txt 高级搜索中存放要过滤的文件夹的路径的值
:: %dati%_8.txt 高级搜索中存放"检查本地磁盘并判断类型"查到的值
:: %dati%_7.txt 高级搜索中存放所有本地磁盘盘符的值
:: %dati%_4.txt 高级搜索中存放直接dir路径未经过滤的值
:: %dati%_6.txt 高级搜索中存放直接dir路径并find names后 未经过滤的值
::
:: %dati%_temp.txt 为了高级搜索后确认是否再进行文件名完全匹配查找而生成的暂时临时文件
:: %dati%_1.txt 模糊搜索中存放要过滤的文件夹的路径的值(默认只是本程序所在当前文件夹)
:: %dati%_2.txt 模糊搜索中存放直接dir路径未经过滤的值
:: %dati%_3.txt 模糊搜索中存放过滤路径后dir的值,第一行空,第二行显示------*.txt
:: %dati%_10.txt 高级搜索dir路径并find names后要find_nx而长生的临时文件
:: g_names.txt 高级搜索中存放要查找的文件名s
:: 原理:通过dir路径|find符合所要搜索文件名的字符串来搜索
:000000
cls
mode con lines=30
title 查找文件并操作(查看路径\复制\删除),记录日志 by:Ye - *
echo ________________________________________________________________________________
echo 使用说明:
echo 复制文件日志 copy_log.txt 复制文件默认复制到目录 copy\
echo 删除文件日志 del_log.txt 删除文件默认备份目录 del_backup\
echo 批量恢复日志 backup_log.txt 搜索到文件时的搜索文件名日志 fc_name.txt
echo ________________________________________________________________________________
echo 注意事项:
echo 1 建议使用时请把本程序放在一个单独的文件夹下,因为默认是不搜索程序当前所在目
echo 录的,还有工作中要生成好多临时文件在目录下
echo 2 输入要查找的文件名时,为了更准确的找到文件请尽量带上后缀
echo 连在一起的字符搜索就好,不要使用*,如搜索***x.txt,直接填x.txt搜索就好
echo 3 输入搜索路径时,如搜索 c 盘则输入 c:\ ,建议去地址栏中直接复制地址粘贴过来
echo 4 任何位置输入半角状态下的以下11个符号中的任何一个都会引起无法预料的错误
echo 它们分别是\、/、:、*、?、"、<、>、(、)、|
echo 除路径中可以输入冒号(紧跟盘符)和反斜杠符号
echo 5 使用本程序建议系统时间使用24小时制
echo ________________________________________________________________________________
echo 按任意键进入查找......
pause>nul
:start
cls
mode con lines=24
echo ________________________________________________________________________________
echo.
echo 模糊搜索:只支持单文件单目录搜索,不支持过滤目录,不支持文件名完全匹配查找
echo.
echo 高级搜索:支持多文件单目录或全盘同时搜索,支持过滤目录,支持文件名完全匹配查找
echo.
echo m 模糊搜索 ^| g 高级搜索
echo ________________________________________________________________________________
set mg_xz=
set /p mg_xz= 请输入操作代码:
if "%mg_xz%"=="" (echo 无效动作 & pause && goto start)
for %%i in (m g) do if %mg_xz%==%%i goto mg_%%i
echo 无效动作 & pause && goto start
:: --------------------------------------------------------------------------------------------------------------------
:mg_m
cls
title 模糊搜索
echo.
echo.
set name=
set lj=
set /p name= 请输入要查找的文件名:
if "%name%"=="" echo 请输入正确的文件名 &pause& goto mg_m
set /p lj= 请输入搜索路径:
if "%lj%"=="" echo 请输入正确的路径 &pause& goto mg_m
echo 请稍侯......
:: 此处获取当前日期时间变量做文件名是为了防止当用一个固定文件名时程序无故终止而这个固定文件名没有删除,可能导至下次查找错误
:: 还有个好处是恢复删除文件方便多了,再后面就会看出
:: 要是不判断比如说凌晨2点,则%dati%的值就像是 06-08-31 20000,中间多了个空格,后面就会出错,我12小时制
if %time:~0,2% lss 10 (set dati=%date:~2,8%0%time:~1,1%%time:~3,2%%time:~6,2%) else (set dati=%date:~2,8%%time:~0,2%%time:~3,2%%time:~6,2%)
:: 不搜索程序当前所在目录
echo %cd%>>%dati%_1.txt
dir /a /s /b "%lj%" |find "%name%">>%dati%_2.txt
for /f "tokens=* delims=" %%i in (%dati%_1.txt) do (find /i /v %dati%_2.txt "%%i">>%dati%_3.txt)
echo.>>%dati%.txt
for /f "skip=2 tokens=* delims=" %%a in (%dati%_3.txt) do (echo %%a>>%dati%.txt)
:: 如果%dati%.txt文件无内容goto no,有则goto ok
findstr . %dati%.txt>nul && (echo %dati%,搜索文件名,%name%,搜索成功>>fc_name.txt & goto ok)||goto no
:: echo 记录以前所有搜索到文件时的搜索文件名,后面利用文件名恢复时用
:: --------------------------------------------------------------------------------------------------------------------
:mg_g
del /q g_names_temp.txt g_names.txt g_names_guolv.txt g_names_guolv_jiance.txt
cls
title 高级搜索
echo ________________________________________________________________________________
echo.
echo 支持多文件名同时搜索(最多5个)
echo.
echo 输入多文件名时,中间用'半脚状态下的逗号'隔开,格式例如:a.txt,b.txt,c.txt,d.txt
echo ________________________________________________________________________________
set names=
set /p names= 请输入要查找的文件名:
if "%names%"=="" echo 请输入正确的文件名 &pause& goto mg_g
echo %names%>g_names_temp.txt
:: 要过滤的文件名
echo windows>>g_names_guolv.txt
echo system32>>g_names_guolv.txt
:: 此处可继续添加文件名过滤,前提是保证格式正确
cd.>g_names_guolv_jiance.txt
for /f "tokens=1 delims=," %%a in (g_names_guolv.txt) do (>>g_names_guolv_jiance.txt findstr /x /i "%%a"<g_names_temp.txt)
echo.
findstr . g_names_guolv_jiance.txt>nul && goto g_names_guolv_jiance_no||goto g_names_guolv_jiance_ok
:g_names_guolv_jiance_no
echo 你输入的%names%文件名含有被过滤的字符,按任意键重新输入别的文件名 &pause>nul& goto mg_g
:g_names_guolv_jiance_ok
for /f "tokens=1,2,3,4,5 delims=," %%i in (g_names_temp.txt) do (
if not "%%i"=="" echo %%i>>g_names.txt
if not "%%j"=="" echo %%j>>g_names.txt
if not "%%k"=="" echo %%k>>g_names.txt
if not "%%l"=="" echo %%l>>g_names.txt
if not "%%m"=="" echo %%m>>g_names.txt
)
del /q g_names_temp.txt g_names_guolv.txt g_names_guolv_jiance.txt
:mg_g_guolv
:: 获取日期+时间变量
set dati=
if %time:~0,2% lss 10 (set dati=%date:~2,8%0%time:~1,1%%time:~3,2%%time:~6,2%) else (set dati=%date:~2,8%%time:~0,2%%time:~3,2%%time:~6,2%)
cls
echo.
echo.
echo 搜索时排除的目录,目录下及子目录下的所有文件将不会被搜索
echo ________________________________________________________________________________
echo.
:mg_g_guolv_zj
set guolv_wjj_zj=
set /p guolv_wjj_zj= 不需要搜索本程序所在的当前文件夹:
if "%guolv_wjj_zj%"=="" (echo 无效动作 & pause && goto mg_g_guolv)
if "%guolv_wjj_zj%"=="y" (echo %cd%>>%dati%_9.txt & goto mg_g_guolv_hsz)
if "%guolv_wjj_zj%"=="n" goto mg_g_guolv_hsz
echo 无效动作 & pause && goto mg_g_guolv
:mg_g_guolv_hsz
echo.
set guolv_wjj_hsz=
set /p guolv_wjj_hsz= 不需要搜索回收站:
if "%guolv_wjj_hsz%"=="" (echo 无效动作 & pause && goto mg_g_guolv)
if "%guolv_wjj_hsz%"=="y" (
@call :dir_all & for /f "tokens=* delims= " %%i in (%dati%_7.txt) do (echo %%iRECYCLER>>%dati%_9.txt)
goto mg_g_guolv_mulu
)
if "%guolv_wjj_hsz%"=="n" goto mg_g_guolv_mulu
echo 无效动作 & pause && goto mg_g_guolv
:mg_g_guolv_mulu
echo.
set guolv_wjj_mulu=
set /p guolv_wjj_mulu= 是否还有不需要搜索的目录:
if "%guolv_wjj_mulu%"=="" (echo 无效动作 & pause && goto mg_g_guolv)
if %guolv_wjj_mulu%==y goto mg_g_guolv_addmulu
if %guolv_wjj_mulu%==n goto mg_g_guolv_end
echo 无效动作 & pause && goto mg_g_guolv
: mg_g_guolv_addmulu
set guolv_wjj_mulus=
set /p guolv_wjj_mulus= 请输入目录的绝对路径(支持输入多路径,路径之间用'半脚状态下的逗号'隔开,留空表示没有不需要搜索的目录):
if "%guolv_wjj_mulus%"=="" goto mg_g_guolv_end
echo %guolv_wjj_mulus%>%dati%_9_temp.txt
for /f "tokens=1,2,3 delims=," %%i in (%dati%_9_temp.txt) do (
if not "%%i"=="" if exist %%i echo %%i>>%dati%_9.txt
if not "%%j"=="" if exist %%j echo %%j>>%dati%_9.txt
if not "%%k"=="" if exist %%k echo %%k>>%dati%_9.txt
)
:: del /q %dati%_9_temp.txt
:mg_g_guolv_end
echo ________________________________________________________________________________
echo 按任意键继续......
pause>nul
:mg_g_qr
cls
echo ________________________________________________________________________________
echo.
echo 你要查找的文件名是:%names%
echo.
echo 不搜索本程序所在的文件夹:%guolv_wjj_zj%
echo.
echo 不搜索回收站:%guolv_wjj_hsz%
echo.
echo 不搜索下列目录:%guolv_wjj_mulus%
echo.
echo 0 返回重新输 ^| y 继续下一步
echo ________________________________________________________________________________
set qr_xz=
set /p qr_xz= 请输入操作代码:
if "%qr_xz%"=="" (echo 无效动作 & pause && goto mg_g_qr)
if "%qr_xz%"=="y" goto mg_g_lj
if "%qr_xz%"=="0" del /q %dati%_9.txt & goto mg_g
echo 无效动作 & pause && goto mg_g_qr
:mg_g_lj
cls
echo ________________________________________________________________________________
echo.
echo 只支持单路径搜索,可以全盘搜索(只限xp sp2),全盘搜索输入all,包括光盘和U盘
echo ________________________________________________________________________________
echo.
set lj=
set /p lj= 请输入搜索路径:
if "%lj%"=="" echo 请输入正确的路径 &pause& goto mg_m_lj
if "%lj%"=="all" goto all_find
echo.
echo 请稍侯......
dir /a /s /b "%lj%">>%dati%_4.txt
dir /ad /s /b "%lj%">>%dati%_fcname_mulu_temp.txt
:fc_guolv_lj
:: dir搜索路径(生成%dati%_4.txt)后find 搜索name (生成%dati%_6_temp.txt) 再 call :find_nx 后生成%dati%_6.txt
for /f "tokens=1 delims=*" %%a in (g_names.txt) do (
>>%dati%_6_temp.txt find /i "%%a"<%dati%_4.txt && call :find_nx %%a
>>%dati%_fcname_mulu.txt find /i "%%a"<%dati%_fcname_mulu_temp.txt
)
:: 下面这句的作用是:比如我们搜索的文件名是abc.exe,而c下正好有个目录abc.exe,在经过上面的那一步后,那么目录c:\abc.exe这个
:: 目录还是存在的,而我们要的是文件名,不是目录,我们经过这一步就可以解决这个问题,windows自带的搜索没有解决这问题
for /f "tokens=1 delims=," %%i in (%dati%_fcname_mulu.txt) do (>>%dati%_6.txt findstr /v /i "%%i"<%dati%_6_temp2.txt)
echo.>>%dati%_temp.txt
:: 如果有%dati%_9.txt文件,就是如果有要过滤的路径,显示%dati%_6.txt中除过滤路径所有路径到%dati%_5.txt
:: 如果没有%dati%_9.txt文件,直接复制%dati%_6.txt 为 %dati%_5.txt 就好
if exist %dati%_9.txt (
for /f "tokens=* delims= " %%a in (%dati%_9.txt) do (>>%dati%_temp.txt find /v /i "%%a"<%dati%_6.txt)
)||copy %dati%_6.txt %dati%_temp.txt
goto fc_temp.txt
:all_find
echo.
echo 请稍侯......全盘搜索可能要多等一会
:: 全盘搜索
if not exist %dati%_7.txt @call :dir_all
for /f "tokens=* delims= " %%i in (%dati%_7.txt) do (
dir /a /s /b "%%i">>%dati%_4.txt & dir /ad /s /b "%%i">>%dati%_fcname_mulu_temp.txt
)
goto fc_guolv_lj
:fc_temp.txt
:: 如果%dati%_temp.txt文件无内容goto no,有则goto ok
findstr . %dati%_temp.txt>nul && (echo %dati%,搜索文件名,%names%,搜索成功>>fc_name.txt & goto ok_temp)||goto no
:: --------------------------------------------------------------------------------------------------------------------
:no
echo.
echo 在路径%lj%中没有找到你要搜索的文件%names%,按任意键重新查找 & del /q 06-*************.txt &pause>nul && goto start
:: --------------------------------------------------------------------------------------------------------------------
:ok_temp
cls
title 是否进行文件名完全匹配查找?
echo ________________________________________________________________________________
echo.
echo y 进行文件名完全匹配查找 ^| n 不进行文件名完全匹配查找
echo ________________________________________________________________________________
set fjq=
set /p fjq= 请输入操作代码:
if "%fjq%"=="" (echo 无效动作 & pause && goto ok_temp)
for %%i in (y,n) do if %fjq%==%%i goto fjq_%%i
echo 无效动作 & pause && goto ok_temp
:fjq_y
cd.>%dati%.txt
for /f "tokens=* delims=*" %%a in (g_names.txt) do (
for /f "skip=1 tokens=*" %%i in (%dati%_temp.txt) do (if /i "%%~nxi"=="%%a" echo %%~dpnxi>>%dati%.txt)
)
findstr . %dati%.txt>nul && (echo %dati%,搜索文件名完全匹配,%names%,搜索成功>>fc_name.txt &del /q %dati%_temp.txt&& goto ok)||goto no
:fjq_n
copy %dati%_temp.txt %dati%.txt && goto ok
:: --------------------------------------------------------------------------------------------------------------------
:: --------------------------------------------------------------------------------------------------------------------
:ok
cls
echo ________________________________________________________________________________
echo 在路径%lj%中成功找到你要查找的文件%name%:
echo.
echo 建议先查看路径列表,符合你愿再执行相关操作,如不符合请修改路径列表
echo 现在的路径列表有重复,建议打开删除重复的
echo.
echo a 退出 ^| b 查看\修改路径列表 ^| c 复制 ^| d 删除 ^| e 恢复删除
echo ________________________________________________________________________________
set xz=
set /p xz= 请输入操作代码:
if "%xz%"=="" (echo 无效动作 & pause && goto ok)
for %%i in (a b c d e) do if %xz%==%%i goto ok_%%i
echo 无效动作 & pause && goto ok
:: ---------------------------------------------------------------------------------------------------
:ok_a
goto end
:: ---------------------------------------------------------------------------------------------------
:ok_b
cls
title 查看\修改路径列表
echo ________________________________________________________________________________
echo.
echo 修改路径列表文件注意事项
echo.
echo 手工删除不需要执行操作的行,整行整行删除,修改后保存
echo 例如: 我在c:\查找abc.txt文件生成的%dati%.txt文件内容如下
echo ╭────────────────────────╮
echo │c:\abc\abc.txt │
echo │c:\abc\abc.txt\ccc.txt │
echo │c:\abc\aaabc.txt │
echo │ │
echo ╰────────────────────────╯
echo 而我不想对 c:\abc\abc.txt\ccc.txt 进行操作,那就把文件内容修改为
echo ╭────────────────────────╮
echo │c:\abc\abc.txt │
echo │c:\abc\aaabc.txt │
echo │ │
echo ╰────────────────────────╯
echo 直接删除c:\abc\abc.txt\ccc.txt那一行,中间不要留空行
echo ________________________________________________________________________________
echo 按任意键打开路径列表文件......
pause>nul & start %dati%.txt & goto ok
:: ---------------------------------------------------------------------------------------------------
:ok_c
cls
title 复制查找到的文件
echo ________________________________________________________________________________
echo.
echo 请把要复制到的文件夹拖曳至本窗口并回车执行操作,不支持手工输入路径
echo.
echo 默认复制到当前目录的copy\%dati%下,如没有此文件夹则自动创建(推荐做法)
echo.
echo y 执行默认 ^| 0 返回上级菜单
echo ________________________________________________________________________________
set clj=
set /p clj= 请输入操作代码:
set "clj=%clj:"=%"
:: 上面这句为判断%clj%中是否存在引号,有则剔除,抄自"文件备份器"
if "%clj%"=="" echo 无效动作 & pause && goto ok_c
if %clj%==0 goto ok
if %clj%==y (
:: 复制并记录日志
md copy\%dati%
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (copy "%%i" copy\%dati%\ )&&(echo %dati%,将源文件,%%i,复制到,copy\%dati%\%%~nxi>>copy_log.txt)
echo ######################################>>copy_log.txt
echo %dati%,搜索文件名,%name%,执行复制 >>fc_name.txt
goto ok
)
if exist "%clj%" (
:: 复制并记录日志
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (copy "%%i" "%clj%\" )&&(echo %dati%,将源文件,%%i,复制到,copy\%dati%\%%~nxi >>copy_log.txt)
echo ######################################>>copy_log.txt
echo %dati%,搜索文件名,%name%,执行复制 >>fc_name.txt
)|echo 请输入正确的路径 &pause& goto ok_c
goto ok
:: ---------------------------------------------------------------------------------------------------
:ok_d
cls
title 删除查找到的文件
echo ________________________________________________________________________________
echo.
echo 此操作危险性高,请再次确认是否删除?
echo.
echo y 确认删除 ^| 0 返回上级菜单
echo ________________________________________________________________________________
set del_=
set /p del_= 请输入操作代码:
if "%del_%"=="" echo 无效动作 & pause && goto ok_d
if %del_%==0 goto ok
if %del_%==y (
:: 先备份后删除
:: 备份
md del_backup\%dati%
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (copy "%%i" del_backup\%dati%\ )&&(echo %dati%,备份已删除文件,%%i,到,del_backup\%dati%\%%~nxi>>del_log.txt)
:: 删除并记录日志
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (del /q /f "%%i")
echo ######################################>>del_log.txt
echo %dati%,搜索文件名,%name%,执行删除 >>fc_name.txt
goto ok
)
echo 无效动作 & pause && goto ok_d
:: ---------------------------------------------------------------------------------------------------
:ok_e
cls
title 恢复已删除的文件
if not exist del_backup\ echo 没有任何可以恢复的文件,按任意键返回上级菜单 &pause>nul&goto ok
echo ________________________________________________________________________________
echo 请根据del_log.txt和备份目录手工写恢复文件列表,执行批量恢复
echo.
echo 列表格式如下: (列表文件名必须为backup.txt)
echo.
echo 逗号左边:要恢复的文件 逗号右边:要恢复到的目录
echo ╭───────────────────────────────╮
echo │del_backup\06-08-31020000\abc.txt,c:\windows\ │
echo │del_backup\06-08-31020000\aaabc.txt,c:\windows\system32\ │
echo │ │
echo │ │
echo ╰───────────────────────────────╯
echo 0 返回上级菜单 ^| a 执行批量恢复
echo ________________________________________________________________________________
set xz_hf=
set /p xz_hf= 请输入操作代码:
if "%xz_hf%"=="" (echo 无效动作 & pause && goto ok_e)
if %xz_hf%==0 goto ok
if %xz_hf%==a goto ok_e_a
echo 无效动作 & pause && goto ok_e
:ok_e_a
if not exist backup.txt echo 没有backup.txt文件,按任意键返回 &pause>nul&goto ok_e
for /f "tokens=1,2 delims=," %%i in (backup.txt) do (copy %%i %%j)&&(echo %dati%,恢复文件,%%i,到目录,%%j>>backup_log.txt)
echo ######################################>>backup_log.txt
echo 完成批量恢复操作 & pause && goto ok
:: ---------------------------------------------------------------------------------------------------
:end
del /q 06-***********.txt
del /q 06-*************.txt
del /q 06-******************.txt
del /q g_names_temp.txt
del /q g_names.txt
del /q
goto start
:: ---------------------------------------------------------------------------------------------------
:: ---------------------------------------------------------------------------------------------------
:: ---------------------------------------------------------------------------------------------------
:: call调用
:dir_all
:: 检查本地磁盘并判断类型,抄自中国dos联盟
:: 如只想搜索本地硬盘则在>>%dati%_8.txt前面加上|find "固定" 既可
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%a in ('fsutil fsinfo drives^|find /v ""') do (
set aa=%%a
set aa=!aa:~-2!
for %%i in (!aa!) do fsutil fsinfo drivetype %%i >>%dati%_8.txt
)
:: 写出本地磁盘盘符到%dati%_7.txt文件下
for /f "tokens=1 delims= " %%a in (%dati%_8.txt) do (echo %%a\>>%dati%_7.txt)
:find_nx
:: 从中再在每个%dati%_6_temp.txt中的路径的
:: 文件名中find 搜索name 并记录符合的路径到%dati%_6.txt , 这样可防止(比如我们搜索的文件名是windows,如果我们不这样做,
:: 那windows下所有文件都会显示在%dati%_6.txt中,因为它们的路径中有搜索name,而文件名中不一定有搜索name)
if not "%1"=="" (
for /f "tokens=1 delims=*" %%a in (%dati%_6_temp.txt) do (
echo "%%~nxa">>%dati%_10.txt & (find /i %dati%_10.txt "%1" &&echo %%~dpnxa>>%dati%_6_temp2.txt||echo.>nul)
del /q %dati%_10.txt
)
)
Last edited by he200377 on 2006-9-6 at 02:52 ]
*.bat
Now there is still a problem, originating from
for /f "tokens=* delims= " %%a in (%dati%_9.txt) do (find %dati%_6.txt /v /i "%%a">>%dati%_5.txt)
In this sentence, there are several repetitions in the generated search file for the number of lines stored in the filtered file. How to fix this?
Now I just want to restore the deletion and start over, making it more automated
@echo off
:: Added logging function on 8-31
:: Added full disk search and exact match search function on 9-1
:: Added multi-file search, can customize and add filtering paths on 9-2
:: Added when searching file names, it detects "the path contains the search file name string but the file name does not" and deletes this path
Added when searching file names, it detects "the path contains the search file name string" and deletes this path, this is just a path
:: Added file name filtering for search on 9-4, preventing users from searching for exactly matching "windows", "system32", etc., users can manually add and delete
:: Explanation of each temporary file
:: %dati%_9.txt stores the path value of the folder to be filtered in advanced search
:: %dati%_8.txt stores the value found by "check local disk and judge type" in advanced search
:: %dati%_7.txt stores all local disk drive letters in advanced search
:: %dati%_4.txt stores the unfiltered value of the direct dir path in advanced search
:: %dati%_6.txt stores the value after directly dir path and find names without filtering in advanced search
::
:: %dati%_temp.txt is a temporary file generated to confirm whether to perform exact file name match search after advanced search
:: %dati%_1.txt stores the path value of the folder to be filtered in fuzzy search (default is just the current folder where the program is located)
:: %dati%_2.txt stores the unfiltered value of the direct dir path in fuzzy search
:: %dati%_3.txt stores the dir value after filtering the path in fuzzy search, the first line is empty, the second line shows ------*.txt
:: %dati%_10.txt is a temporary file generated by find_nx after dir path and find names in advanced search
:: g_names.txt stores the file names to be searched in advanced search
:: Principle: Search by dir path | find the string that meets the desired search file name
:000000
cls
mode con lines=30
title Find Files and Operate(View Path\Copy\Delete), Record Log by:Ye - *
echo ________________________________________________________________________________
echo Instructions:
echo Copy File Log copy_log.txt Default copy directory for copied files copy\
echo Delete File Log del_log.txt Default backup directory for deleted files del_backup\
echo Batch Restore Log backup_log.txt Search file name log when searching for files fc_name.txt
echo ________________________________________________________________________________
echo Precautions:
echo 1 It is recommended to put this program in a separate folder when using it, because it is not the default to search the current directory where the program is located, and there are many temporary files generated in the directory during work
echo 2 When entering the file name to be searched, please try to bring the suffix as accurately as possible to find the file. Do not use *, for example, search ***x.txt, just enter x.txt to search
echo 3 When entering the search path, if searching the C drive, enter c:\, it is recommended to directly copy the address from the address bar and paste it
echo 4 Entering any of the following 11 symbols in half-width state in any position will cause unexpected errors
echo They are \, /, :, *, ?, ", <, >, (, ), |
echo Except that colons (immediately following the drive letter) and backslash symbols can be entered in the path
echo 5 It is recommended to use 24-hour system for system time when using this program
echo ________________________________________________________________________________
echo Press any key to enter the search......
pause>nul
:start
cls
mode con lines=24
echo ________________________________________________________________________________
echo.
echo Fuzzy search: Only supports single file single directory search, does not support filtering directories, does not support exact file name match search
echo.
echo Advanced search: Supports multi-file single directory or full disk search at the same time, supports filtering directories, supports exact file name match search
echo.
echo m Fuzzy search ^| g Advanced search
echo ________________________________________________________________________________
set mg_xz=
set /p mg_xz= Please enter the operation code:
if "%mg_xz%"=="" (echo Invalid action & pause && goto start)
for %%i in (m g) do if %mg_xz%==%%i goto mg_%%i
echo Invalid action & pause && goto start
:: --------------------------------------------------------------------------------------------------------------------
:mg_m
cls
title Fuzzy Search
echo.
echo.
set name=
set lj=
set /p name= Please enter the file name to search for:
if "%name%"=="" echo Please enter the correct file name &pause& goto mg_m
set /p lj= Please enter the search path:
if "%lj%"=="" echo Please enter the correct path &pause& goto mg_m
echo Please wait......
:: Here, the current date and time variable is obtained to make the file name to prevent the program from unexpectedly terminating when using a fixed file name and this fixed file name is not deleted, which may lead to errors in the next search
:: There is also a benefit that it is much more convenient to restore deleted files, which will be seen later
:: If not judged, for example, at 2:00 in the morning, the value of %dati% is like 06-08-31 20000, with an extra space in the middle, which will cause errors later. I use 12-hour system
if %time:~0,2% lss 10 (set dati=%date:~2,8%0%time:~1,1%%time:~3,2%%time:~6,2%) else (set dati=%date:~2,8%%time:~0,2%%time:~3,2%%time:~6,2%)
:: Do not search the current directory where the program is located
echo %cd%>>%dati%_1.txt
dir /a /s /b "%lj%" |find "%name%">>%dati%_2.txt
for /f "tokens=* delims=" %%i in (%dati%_1.txt) do (find /i /v %dati%_2.txt "%%i">>%dati%_3.txt)
echo.>>%dati%.txt
for /f "skip=2 tokens=* delims=" %%a in (%dati%_3.txt) do (echo %%a>>%dati%.txt)
:: If the %dati%.txt file has no content, goto no, if it has content, goto ok
findstr . %dati%.txt>nul && (echo %dati%,Search file name,%name%,Search successful>>fc_name.txt & goto ok)||goto no
:: echo Record the file name when all previous searched files were found, and later use the file name to restore
:: --------------------------------------------------------------------------------------------------------------------
:mg_g
del /q g_names_temp.txt g_names.txt g_names_guolv.txt g_names_guolv_jiance.txt
cls
title Advanced Search
echo ________________________________________________________________________________
echo.
echo Supports searching multiple file names at the same time (up to 5)
echo.
echo When entering multiple file names, separate them with 'comma in half-width state', for example: a.txt,b.txt,c.txt,d.txt
echo ________________________________________________________________________________
set names=
set /p names= Please enter the file name to search for:
if "%names%"=="" echo Please enter the correct file name &pause& goto mg_g
echo %names%>g_names_temp.txt
:: File names to be filtered
echo windows>>g_names_guolv.txt
echo system32>>g_names_guolv.txt
:: You can continue to add file name filtering here, provided that the format is correct
cd.>g_names_guolv_jiance.txt
for /f "tokens=1 delims=," %%a in (g_names_guolv.txt) do (>>g_names_guolv_jiance.txt findstr /x /i "%%a"<g_names_temp.txt)
echo.
findstr . g_names_guolv_jiance.txt>nul && goto g_names_guolv_jiance_no||goto g_names_guolv_jiance_ok
:g_names_guolv_jiance_no
echo The file name %names% you entered contains filtered characters, press any key to re-enter other file names &pause>nul& goto mg_g
:g_names_guolv_jiance_ok
for /f "tokens=1,2,3,4,5 delims=," %%i in (g_names_temp.txt) do (
if not "%%i"=="" echo %%i>>g_names.txt
if not "%%j"=="" echo %%j>>g_names.txt
if not "%%k"=="" echo %%k>>g_names.txt
if not "%%l"=="" echo %%l>>g_names.txt
if not "%%m"=="" echo %%m>>g_names.txt
)
del /q g_names_temp.txt g_names_guolv.txt g_names_guolv_jiance.txt
:mg_g_guolv
:: Get date + time variable
set dati=
if %time:~0,2% lss 10 (set dati=%date:~2,8%0%time:~1,1%%time:~3,2%%time:~6,2%) else (set dati=%date:~2,8%%time:~0,2%%time:~3,2%%time:~6,2%)
cls
echo.
echo.
echo Directories to be excluded during search, all files under and in subdirectories of the directory will not be searched
echo ________________________________________________________________________________
echo.
:mg_g_guolv_zj
set guolv_wjj_zj=
set /p guolv_wjj_zj= Do you not want to search the current folder where the program is located:
if "%guolv_wjj_zj%"=="" (echo Invalid action & pause && goto mg_g_guolv)
if "%guolv_wjj_zj%"=="y" (echo %cd%>>%dati%_9.txt & goto mg_g_guolv_hsz)
if "%guolv_wjj_zj%"=="n" goto mg_g_guolv_hsz
echo Invalid action & pause && goto mg_g_guolv
:mg_g_guolv_hsz
echo.
set guolv_wjj_hsz=
set /p guolv_wjj_hsz= Do you not want to search the Recycle Bin:
if "%guolv_wjj_hsz%"=="" (echo Invalid action & pause && goto mg_g_guolv)
if "%guolv_wjj_hsz%"=="y" (
@call :dir_all & for /f "tokens=* delims= " %%i in (%dati%_7.txt) do (echo %%iRECYCLER>>%dati%_9.txt)
goto mg_g_guolv_mulu
)
if "%guolv_wjj_hsz%"=="n" goto mg_g_guolv_mulu
echo Invalid action & pause && goto mg_g_guolv
:mg_g_guolv_mulu
echo.
set guolv_wjj_mulu=
set /p guolv_wjj_mulu= Is there any other directory you do not want to search:
if "%guolv_wjj_mulu%"=="" (echo Invalid action & pause && goto mg_g_guolv)
if %guolv_wjj_mulu%==y goto mg_g_guolv_addmulu
if %guolv_wjj_mulu%==n goto mg_g_guolv_end
echo Invalid action & pause && goto mg_g_guolv
: mg_g_guolv_addmulu
set guolv_wjj_mulus=
set /p guolv_wjj_mulus= Please enter the absolute path of the directory (supports entering multiple paths, separate paths with 'comma in half-width state', leave blank if there are no directories you do not want to search):
if "%guolv_wjj_mulus%"=="" goto mg_g_guolv_end
echo %guolv_wjj_mulus%>%dati%_9_temp.txt
for /f "tokens=1,2,3 delims=," %%i in (%dati%_9_temp.txt) do (
if not "%%i"=="" if exist %%i echo %%i>>%dati%_9.txt
if not "%%j"=="" if exist %%j echo %%j>>%dati%_9.txt
if not "%%k"=="" if exist %%k echo %%k>>%dati%_9.txt
)
:: del /q %dati%_9_temp.txt
:mg_g_guolv_end
echo ________________________________________________________________________________
echo Press any key to continue......
pause>nul
:mg_g_qr
cls
echo ________________________________________________________________________________
echo.
echo The file name you want to search for is:%names%
echo.
echo Do you not want to search the folder where the program is located:%guolv_wjj_zj%
echo.
echo Do you not want to search the Recycle Bin:%guolv_wjj_hsz%
echo.
echo Directories not to be searched:%guolv_wjj_mulus%
echo.
echo 0 Return to re-enter ^| y Continue to next step
echo ________________________________________________________________________________
set qr_xz=
set /p qr_xz= Please enter the operation code:
if "%qr_xz%"=="" (echo Invalid action & pause && goto mg_g_qr)
if "%qr_xz%"=="y" goto mg_g_lj
if "%qr_xz%"=="0" del /q %dati%_9.txt & goto mg_g
echo Invalid action & pause && goto mg_g_qr
:mg_g_lj
cls
echo ________________________________________________________________________________
echo.
echo Only supports single path search, can search the entire disk (only for xp sp2), enter all for full disk search, including CDs and USB drives
echo ________________________________________________________________________________
echo.
set lj=
set /p lj= Please enter the search path:
if "%lj%"=="" echo Please enter the correct path &pause& goto mg_m_lj
if "%lj%"=="all" goto all_find
echo.
echo Please wait......
dir /a /s /b "%lj%">>%dati%_4.txt
dir /ad /s /b "%lj%">>%dati%_fcname_mulu_temp.txt
:fc_guolv_lj
:: After dir search path (generate %dati%_4.txt) find search name (generate %dati%_6_temp.txt) then call :find_nx to generate %dati%_6.txt
for /f "tokens=1 delims=*" %%a in (g_names.txt) do (
>>%dati%_6_temp.txt find /i "%%a"<%dati%_4.txt && call :find_nx %%a
>>%dati%_fcname_mulu.txt find /i "%%a"<%dati%_fcname_mulu_temp.txt
)
:: The role of the following sentence is: for example, the file name we search for is abc.exe, and there happens to be a directory abc.exe under c. After the above step, then the directory c:\abc.exe this
:: directory still exists, and what we want is the file name, not the directory. We can solve this problem through this step. The windows built-in search does not solve this problem
for /f "tokens=1 delims=," %%i in (%dati%_fcname_mulu.txt) do (>>%dati%_6.txt findstr /v /i "%%i"<%dati%_6_temp2.txt)
echo.>>%dati%_temp.txt
:: If there is a %dati%_9.txt file, that is, if there are paths to be filtered, display all paths in %dati%_6.txt except the filtered paths to %dati%_5.txt
:: If there is no %dati%_9.txt file, just copy %dati%_6.txt to %dati%_5.txt
if exist %dati%_9.txt (
for /f "tokens=* delims= " %%a in (%dati%_9.txt) do (>>%dati%_temp.txt find /v /i "%%a"<%dati%_6.txt)
)||copy %dati%_6.txt %dati%_temp.txt
goto fc_temp.txt
:all_find
echo.
echo Please wait......Full disk search may take more time
:: Full disk search
if not exist %dati%_7.txt @call :dir_all
for /f "tokens=* delims= " %%i in (%dati%_7.txt) do (
dir /a /s /b "%%i">>%dati%_4.txt & dir /ad /s /b "%%i">>%dati%_fcname_mulu_temp.txt
)
goto fc_guolv_lj
:fc_temp.txt
:: If the %dati%_temp.txt file has no content, goto no, if it has content, goto ok
findstr . %dati%_temp.txt>nul && (echo %dati%,Search file name,%names%,Search successful>>fc_name.txt & goto ok_temp)||goto no
:: --------------------------------------------------------------------------------------------------------------------
:no
echo.
echo The file %names% you want to search for was not found in the path %lj%, press any key to re-search & del /q 06-*************.txt &pause>nul && goto start
:: --------------------------------------------------------------------------------------------------------------------
:ok_temp
cls
title Do you want to perform exact file name match search?
echo ________________________________________________________________________________
echo.
echo y Perform exact file name match search ^| n Do not perform exact file name match search
echo ________________________________________________________________________________
set fjq=
set /p fjq= Please enter the operation code:
if "%fjq%"=="" (echo Invalid action & pause && goto ok_temp)
for %%i in (y,n) do if %fjq%==%%i goto fjq_%%i
echo Invalid action & pause && goto ok_temp
:fjq_y
cd.>%dati%.txt
for /f "tokens=* delims=*" %%a in (g_names.txt) do (
for /f "skip=1 tokens=*" %%i in (%dati%_temp.txt) do (if /i "%%~nxi"=="%%a" echo %%~dpnxi>>%dati%.txt)
)
findstr . %dati%.txt>nul && (echo %dati%,Search file name exactly match,%names%,Search successful>>fc_name.txt &del /q %dati%_temp.txt&& goto ok)||goto no
:fjq_n
copy %dati%_temp.txt %dati%.txt && goto ok
:: --------------------------------------------------------------------------------------------------------------------
:: --------------------------------------------------------------------------------------------------------------------
:ok
cls
echo ________________________________________________________________________________
echo Successfully found the file %name% you want to search for in the path %lj%:
echo.
echo It is recommended to view the path list first, perform related operations if it meets your wishes, and modify the path list if it does not meet
echo There are duplicates in the current path list, it is recommended to open and delete duplicates
echo.
echo a Exit ^| b View/Modify Path List ^| c Copy ^| d Delete ^| e Restore Deletion
echo ________________________________________________________________________________
set xz=
set /p xz= Please enter the operation code:
if "%xz%"=="" (echo Invalid action & pause && goto ok)
for %%i in (a b c d e) do if %xz%==%%i goto ok_%%i
echo Invalid action & pause && goto ok
:: ---------------------------------------------------------------------------------------------------
:ok_a
goto end
:: ---------------------------------------------------------------------------------------------------
:ok_b
cls
title View/Modify Path List
echo ________________________________________________________________________________
echo.
echo Precautions for manually deleting path list file
echo.
echo Manually delete the lines that do not need to be operated, delete the entire line, and save after modification
echo For example: The content of the %dati%.txt file generated when I search for abc.txt in c:\ is as follows
echo ╭────────────────────────╮
echo │c:\abc\abc.txt │
echo │c:\abc\abc.txt\ccc.txt │
echo │c:\abc\aaabc.txt │
echo │ │
echo ╰────────────────────────╯
echo And I don't want to operate c:\abc\abc.txt\ccc.txt, then modify the file content to
echo ╭────────────────────────╮
echo │c:\abc\abc.txt │
echo │c:\abc\aaabc.txt │
echo │ │
echo ╰────────────────────────╯
echo Directly delete the line c:\abc\abc.txt\ccc.txt, do not leave blank lines in the middle
echo ________________________________________________________________________________
echo Press any key to open the path list file......
pause>nul & start %dati%.txt & goto ok
:: ---------------------------------------------------------------------------------------------------
:ok_c
cls
title Copy Found Files
echo ________________________________________________________________________________
echo.
echo Please drag and drop the folder to copy to into this window and press Enter to perform the operation, manual input of the path is not supported
echo.
echo The default is to copy to copy\%dati% under the current directory, and if there is no such folder, it will be automatically created (recommended practice)
echo.
echo y Perform default ^| 0 Return to previous menu
echo ________________________________________________________________________________
set clj=
set /p clj= Please enter the operation code:
set "clj=%clj:"=%"
:: The above sentence is to judge whether there are quotes in %clj%, and remove them if there are, copied from "File Backup Tool"
if "%clj%"=="" echo Invalid action & pause && goto ok_c
if %clj%==0 goto ok
if %clj%==y (
:: Copy and record log
md copy\%dati%
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (copy "%%i" copy\%dati%\ )&&(echo %dati%,Copy source file,%%i,to,copy\%dati%\%%~nxi>>copy_log.txt)
echo ######################################>>copy_log.txt
echo %dati%,Search file name,%name%,Perform copy >>fc_name.txt
goto ok
)
if exist "%clj%" (
:: Copy and record log
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (copy "%%i" "%clj%\" )&&(echo %dati%,Copy source file,%%i,to,copy\%dati%\%%~nxi >>copy_log.txt)
echo ######################################>>copy_log.txt
echo %dati%,Search file name,%name%,Perform copy >>fc_name.txt
)|echo Please enter the correct path &pause& goto ok_c
goto ok
:: ---------------------------------------------------------------------------------------------------
:ok_d
cls
title Delete Found Files
echo ________________________________________________________________________________
echo.
echo This operation is highly dangerous, please confirm again whether to delete?
echo.
echo y Confirm Delete ^| 0 Return to previous menu
echo ________________________________________________________________________________
set del_=
set /p del_= Please enter the operation code:
if "%del_%"=="" echo Invalid action & pause && goto ok_d
if %del_%==0 goto ok
if %del_%==y (
:: Backup first, then delete
:: Backup
md del_backup\%dati%
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (copy "%%i" del_backup\%dati%\ )&&(echo %dati%,Backup deleted file,%%i,to,del_backup\%dati%\%%~nxi>>del_log.txt)
:: Delete and record log
for /f "skip=1 tokens=* delims=" %%i in (%dati%.txt) do (del /q /f "%%i")
echo ######################################>>del_log.txt
echo %dati%,Search file name,%name%,Perform delete >>fc_name.txt
goto ok
)
echo Invalid action & pause && goto ok_d
:: ---------------------------------------------------------------------------------------------------
:ok_e
cls
title Restore Deleted Files
if not exist del_backup\ echo No files that can be restored, press any key to return to previous menu &pause>nul&goto ok
echo ________________________________________________________________________________
echo Please manually write the restore file list according to del_log.txt and backup directory, and perform batch restore
echo.
echo The list format is as follows: (The list file name must be backup.txt)
echo.
echo Left of comma: File to be restored Right of comma: Directory to restore to
echo ╭───────────────────────────────╮
echo │del_backup\06-08-31020000\abc.txt,c:\windows\ │
echo │del_backup\06-08-31020000\aaabc.txt,c:\windows\system32\ │
echo │ │
echo │ │
echo ╰───────────────────────────────╯
echo 0 Return to previous menu ^| a Perform Batch Restore
echo ________________________________________________________________________________
set xz_hf=
set /p xz_hf= Please enter the operation code:
if "%xz_hf%"=="" (echo Invalid action & pause && goto ok_e)
if %xz_hf%==0 goto ok
if %xz_hf%==a goto ok_e_a
echo Invalid action & pause && goto ok_e
:ok_e_a
if not exist backup.txt echo No backup.txt file, press any key to return &pause>nul&goto ok_e
for /f "tokens=1,2 delims=," %%i in (backup.txt) do (copy %%i %%j)&&(echo %dati%,Restore file,%%i,to directory,%%j>>backup_log.txt)
echo ######################################>>backup_log.txt
echo Batch restore operation completed & pause && goto ok
:: ---------------------------------------------------------------------------------------------------
:end
del /q 06-***********.txt
del /q 06-*************.txt
del /q 06-******************.txt
del /q g_names_temp.txt
del /q g_names.txt
del /q
goto start
:: ---------------------------------------------------------------------------------------------------
:: ---------------------------------------------------------------------------------------------------
:: ---------------------------------------------------------------------------------------------------
:: call call
:dir_all
:: Check local disk and judge type, copied from China DOS Union
:: If you only want to search local hard drives, you can add |find "fixed" in front of >>%dati%_8.txt
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%a in ('fsutil fsinfo drives^|find /v ""') do (
set aa=%%a
set aa=!aa:~-2!
for %%i in (!aa!) do fsutil fsinfo drivetype %%i >>%dati%_8.txt
)
:: Write local disk drive letters to the %dati%_7.txt file
for /f "tokens=1 delims= " %%a in (%dati%_8.txt) do (echo %%a\>>%dati%_7.txt)
:find_nx
:: From then find in the file name of each path in %dati%_6_temp.txt
:: Search name and record the path that meets the requirements to %dati%_6.txt, this can prevent (for example, the file name we search for is windows, if we don't do this,
:: Then all files under windows will be displayed in %dati%_6.txt, because their paths contain the search name, but the file name may not contain the search name)
if not "%1"=="" (
for /f "tokens=1 delims=*" %%a in (%dati%_6_temp.txt) do (
echo "%%~nxa">>%dati%_10.txt & (find /i %dati%_10.txt "%1" &&echo %%~dpnxa>>%dati%_6_temp2.txt||echo.>nul)
del /q %dati%_10.txt
)
)
Last edited by he200377 on 2006-9-6 at 02:52 ]
|
|
2006-8-31 14:02 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
不错不错,比较有实用性。
当然,瑕疵也是有的,并且有些可能会导致很严重的后果:
1、对于每用set /p设置的变量,在接收用户的输入之前,都应该设置成空值,否则,下次再goto start回来之后,连续按几个回车键,将重复上次的操作,可能会导致用户数据的损失;
2、一旦要接收用户的输入,就应该有几句输入错误检测语句,对比较严重的输入错误进行检测,以防意外;
3、要随时注意对含空格字符串的处理;比如:copy %%i,%%i 的值就有可能存在空格,不用引号引起来是会出错的;for "delims=," %%i in (a.txt) 一句中似乎应该加一句 tokens=* 、del %%i 中用引号把 %%i 括起来……类似的地方还有好几处,请注意修改;
4、执行过程中,可能等待的时间较长,应该在屏幕上有所提示,无关的信息应该cls掉;
楼主如果能再完善一下的话,这个脚本就更好用了。
Last edited by namejm on 2006-8-31 at 15:00 ]
Not bad, relatively practical.
Of course, there are also flaws, and some may lead to very serious consequences:
1. For each variable set by set /p, the variable should be set to an empty value before receiving user input; otherwise, after returning to goto start next time, pressing a few Enter keys continuously will repeat the previous operation, which may cause loss of user data;
2. Once user input is to be received, there should be a few input error detection statements to detect more serious input errors to prevent accidents;
3. Always pay attention to the processing of strings with spaces; for example: copy %%i, the value of %%i may have spaces, and it will be wrong if not enclosed in quotes; in the sentence for "delims=," %%i in (a.txt), it seems that a sentence tokens=* should be added, and the %%i in del %%i should be enclosed in quotes with %%i... There are several similar places, please pay attention to modification;
4. During the execution process, there may be a long waiting time, so there should be a prompt on the screen, and irrelevant information should be cls'ed;
If the building owner can improve it a little more, this script will be more useful.
Last edited by namejm on 2006-8-31 at 15:00 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-31 14:55 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
谢谢楼上的指导
第1条 我确实没有想到,这个应该注意
第2条 我想应该还要屏蔽 , | & 和 空格,因为我试了只要在输入状态下只要输入这几个字符就强制退出了,这个是懒没有加上过滤,哎
第3条 恩,这样改好点
第4条 我认为执行很快的,就2s左右,就没有写上提示
楼上帮我改该~呵呵,先谢谢了,我看看具体哪些地方我没有注意到
Last edited by he200377 on 2006-8-31 at 15:15 ]
Thanks to the guidance from the person above.
Item 1: I really didn't think of this, this should be noted.
Item 2: I think I should also block, | & and spaces, because I tried that as long as these characters are input in the input state, it will force to exit. This is because I was lazy and didn't add filtering. Oh.
Item 3: Hmm, this modification is better.
Item 4: I think the execution is very fast, about 2s, so I didn't write a prompt.
Please help me modify it~ Hehe, thank you first. I'll see which places I didn't notice specifically.
Last edited by he200377 on 2006-8-31 at 15:15 ]
|
|
2006-8-31 15:13 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Originally posted by he200377 at 2006-8-31 15:13:
第2条 我想应该还要屏蔽 , | & 和 空格,因为我试了只要在输入状态下只要输入这几个字符就强制退出了,这个是懒没有加上过滤,哎
——|、&等字符属于CMD的敏感字符,你是没法过滤掉的,只有空格还行
第4条 我认为执行很快的,就2s左右,就没有写上提示
——如果用户指定了多个路径,或者某个路径下的子文件夹及文件很多的话,搜索的时间就不会只有区区两秒钟了,看来你的测试条件没有上足
其实还有几个地方要修改的:比如第二句的 cmd /c 就显得多余了;若要吹毛求疵的话,还是可以找到一些的。
Originally posted by he200377 at 2006-8-31 15:13:
Article 2 I think it should also be blocked, | & and spaces, because I tried that as long as these characters are entered in the input state, it will force exit. This is because I was lazy and did not add filtering. Hey
——|, & and other characters are sensitive characters of CMD, you can't filter them out, only spaces are okay
Article 4 I think the execution is very fast, about 2s, so I didn't write the prompt
——If the user specifies multiple paths, or there are many subfolders and files under a certain path, the search time will not be only two seconds. It seems that your test conditions are not sufficient
In fact, there are still a few places to modify: for example, the cmd /c in the second sentence is redundant; if you want to be overly critical, some can still be found.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-31 17:14 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
来一个修改版本,只修改了前面提到的大部分问题,并把容易引起误解的提示语句稍作修改,输入错误检测那一段要考虑的情况比较多,暂时没时间去完善;查询的时候添加什么提示信息,楼主可以自行决定,我就不去添加了;楼主可以对比一下前后的代码,在需要完善的地方继续修改:
@echo off
:start
cls
title 查找文件并操作(查看路径\复制\删除)
set name=
set /p name=请输入要查找的文件名(最好带后缀名):
set lj=
set /p lj=请输入搜索路径(如搜索c盘请输入c:\):
dir /a /s /b "%lj%" |find "%name%" >a.txt
if errorlevel 1 goto no
if errorlevel 0 goto ok
:no
echo 没有你找的文件 & pause && goto end
:ok
cls
echo ________________________________________________________________
echo 找到文件:
echo.
echo a 查看路径 ^| b 退出 ^| c 复制 ^| d 删除
echo ________________________________________________________________
set xz=
set /p xz= 请输入操作代码:
if not "%xz%"=="" (goto ok_%xz%) else (echo 无效动作 & pause && goto ok)
echo 无效动作 & pause && goto ok
:ok_a
cls
title 查看查找到的文件路径
type a.txt &pause& goto ok
:ok_b
goto end
:ok_c
cls
title 复制查找到的文件
echo ________________________________________________________________
echo.
echo 默认复制到当前目录的temp文件夹下,如没有temp文件夹则自动创建
echo.
echo y 执行默认 ^| 0 返回上级菜单
echo ________________________________________________________________
set clj=
set /p clj= 请输入要复制到的位置:
if %clj%==0 goto ok
if %clj%==y md temp & for /f "tokens=* delims=" %%i in (a.txt) do copy "%%i" temp\
for /f "tokens=* delims=" %%i in (a.txt) do copy "%%i" "%clj%\"
goto end
:ok_d
cls
title 删除查找到的文件
echo ________________________________________________________________
echo.
echo 此操作危险性高,请再次确认要删除?
echo.
echo y 确认 ^| 0 返回上级菜单
echo ________________________________________________________________
set del_=
set /p del_= 请选择:
if "%del_%"=="" echo 无效动作 & pause && goto ok
if %del_%==0 goto ok
if %del_%==y for /f "tokens=* delims=" %%i in (a.txt) do del /q /f "%%i"
echo 无效动作 & pause && goto ok
:end
del /q a.txt
goto start
Last edited by namejm on 2006-8-31 at 17:27 ]
Here is the translated text:
Come with a modified version, only modified most of the problems mentioned earlier, and slightly modified the prompt statements that are easy to cause misunderstandings. The situation in the input error detection part needs to be improved, but there is no time to perfect it for the time being; when querying, what prompt information to add, the original poster can decide by themselves, so I won't add it; the original poster can compare the previous and subsequent codes and continue to modify where improvement is needed:
@echo off
:start
cls
title Find and operate files (view path\copy\delete)
set name=
set /p name=Please enter the file name to be found (it is best to bring the suffix name):
set lj=
set /p lj=Please enter the search path (for example, enter c:\ if searching the C drive):
dir /a /s /b "%lj%" |find "%name%" >a.txt
if errorlevel 1 goto no
if errorlevel 0 goto ok
:no
echo There is no file you are looking for & pause && goto end
:ok
cls
echo ________________________________________________________________
echo Found file:
echo.
echo a View path ^| b Exit ^| c Copy ^| d Delete
echo ________________________________________________________________
set xz=
set /p xz= Please enter the operation code:
if not "%xz%"=="" (goto ok_%xz%) else (echo Invalid action & pause && goto ok)
echo Invalid action & pause && goto ok
:ok_a
cls
title View the path of the found file
type a.txt &pause& goto ok
:ok_b
goto end
:ok_c
cls
title Copy the found file
echo ________________________________________________________________
echo.
echo The default is to copy to the temp folder of the current directory. If there is no temp folder, it will be created automatically
echo.
echo y Execute default ^| 0 Return to the previous menu
echo ________________________________________________________________
set clj=
set /p clj= Please enter the location to copy to:
if %clj%==0 goto ok
if %clj%==y md temp & for /f "tokens=* delims=" %%i in (a.txt) do copy "%%i" temp\
for /f "tokens=* delims=" %%i in (a.txt) do copy "%%i" "%clj%\"
goto end
:ok_d
cls
title Delete the found file
echo ________________________________________________________________
echo.
echo This operation is highly dangerous, please confirm again that you want to delete?
echo.
echo y Confirm ^| 0 Return to the previous menu
echo ________________________________________________________________
set del_=
set /p del_= Please choose:
if "%del_%"=="" echo Invalid action & pause && goto ok
if %del_%==0 goto ok
if %del_%==y for /f "tokens=* delims=" %%i in (a.txt) do del /q /f "%%i"
echo Invalid action & pause && goto ok
:end
del /q a.txt
goto start
Last edited by namejm on 2006-8-31 at 17:27 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-31 17:22 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
谢谢,我回去再看看
Thanks, I'll go back and take another look
|
|
2006-8-31 18:11 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
做个记号
是因为用到了 call :标号 参数
Make a mark
Because it uses call: label parameter
附件
1: 做恢复删除的时候想到的.rar (2006-9-1 13:23, 871 bytes, 下载附件所需积分 1 点
,下载次数: 62)
|
|
2006-9-1 13:23 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Re he200377顶楼:
你现在的代码存在一个致命的错误:dir /a /s /b "%lj%" |find "%name%" >%dati%.txt,这条语句是无法实现查询的,所以我把相关的语句修改了一下,实现了你想要的完全匹配查找的意图:
cd.>%dati%.txt
for /f "tokens=*" %%i in ('dir /a /s /b "%lj%"') do (
if /i "%%~nxi"=="%name%" echo %%~dpnxi>>%dati%.txt
)
findstr . %dati%.txt>nul && (echo %dati%,搜索文件名,%name%,搜索成功>>fc_name.txt & goto ok)||goto no
至于不搜索脚本文件所在的目录,暂时还没想到高效的办法,变通的做法是从查找到的结果中把脚本文件所在目录的记录删除。
其他的小问题还是存在的:比如,每次查询之前,都要把日志内容清空,免得和上一次的结果混在一起。
Re he200377's top post:
The code you have now has a fatal error: The statement dir /a /s /b "%lj%" |find "%name%" >%dati%.txt cannot achieve the query, so I modified the relevant statement to achieve the intention of the exact match search you wanted:
cd.>%dati%.txt
for /f "tokens=*" %%i in ('dir /a /s /b "%lj%"') do (
if /i "%%~nxi"=="%name%" echo %%~dpnxi>>%dati%.txt
)
findstr . %dati%.txt>nul && (echo %dati%,Search file name,%name%,Search successful>>fc_name.txt & goto ok)||goto no
As for not searching the directory where the script file is located, I haven't thought of an efficient way for the time being. The alternative is to delete the records of the directory where the script file is located from the found results.
There are still other small problems: For example, before each query, you need to clear the log content to avoid mixing with the previous results.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-1 17:17 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by he200377 at 2006-9-1 13:23:
做个记号
是因为用到了 call :标号 参数
没明白你发这个帖子的意图,请说明一下好吗?
Originally posted by he200377 at 2006-9-1 13:23:
Make a mark
It's because of using call :label parameter
I don't understand the intention of your posting this thread. Could you please explain it?
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-1 17:18 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
比如,每次查询之前,都要把日志内容清空,免得和上一次的结果混在一起
每次生成的文件是已日期+时间(精确到到s)来命名的,所以就算中间中断也没有关系的,原理上说是不会生成一个同名文件的
Last edited by he200377 on 2006-9-1 at 17:39 ]
For example, before each query, you need to clear the log content to avoid mixing with the results of the previous time.
The file generated each time is named with the date + time (precise to seconds), so even if there is an interruption in the middle, it doesn't matter. In principle, the same - named file will not be generated.
Last edited by he200377 on 2006 - 9 - 1 at 17:39 ]
|
|
2006-9-1 17:29 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by namejm at 2006-9-1 17:18:
没明白你发这个帖子的意图,请说明一下好吗?
只是在测试的时候想到了用就试着用了下
Originally posted by namejm at 2006-9-1 17:18:
I didn't understand the intention of your posting this thread, could you please explain it?
Just thought of using it during testing and tried it out
|
|
2006-9-1 17:31 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
不明白这个? "%%~nxi" 那到是文件名,查了下以前的帖子 ~dp是路径,我想这个就是文件名了
//试了下明白了
Last edited by he200377 on 2006-9-1 at 17:48 ]
Don't understand this? "%%~nxi" is the file name. Checked previous posts ~dp is the path, I think this is the file name.
//Tried it and understood
Last edited by he200377 on 2006-9-1 at 17:48 ]
|
|
2006-9-1 17:39 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by he200377 at 2006-9-1 17:29:
比如,每次查询之前,都要把日志内容清空,免得和上一次的结果混在一起
每次生成的文件是已日期+时间(精确到到s)来命名的,所以就算中间丠...
你还是漏掉了一个非常重要的文件:fc_name.txt。这个文件你漏掉的话,麻烦就大了——如果你分几次查询不同的文件,然后直接就选了删除,嘿嘿,你就等着哭鼻子吧:P
Originally posted by he200377 at 2006-9-1 17:29:
For example, before each query, you need to clear the log content to avoid mixing with the previous results
Each generated file is named with the date + time (precise to seconds), so even if there are...
You still missed a very important file: fc_name.txt. If you miss this file, it will be a big problem - if you query different files several times and then directly select delete, heh heh, just wait to cry nose吧:P
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-1 22:09 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
全盘查找指定文件的功能,我头两天弄了一个,发出来给你借鉴一下吧。
@echo off
:: 全盘搜索指定的文件
:: 注意文件夹的跳转,要在盘符后加\,或者先回到根目录之后再用cd /d来跳
:: 否则,在桌面上的时候无法直接用cd /d来跳转到系统盘根目录
setlocal enabledelayedexpansion
for %%i in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%i:\nul (
for /f "tokens=3" %%z in ('dir /-c %%i:\') do set freesize=%%z
if not "!freesize!"=="0" (
pushd %%i:\
for /r %%k in (.) do (
if exist %%k\icon.ico echo %%k\icon.ico
)
)
)
)
popd
pause
Last edited by namejm on 2006-9-1 at 23:08 ]
The function of searching for a specified file throughout the entire disk. I made one the other day, and I'll post it for you to refer to.
@echo off
:: Search for a specified file throughout the entire disk
:: Note the jump of folders. You need to add \ after the drive letter, or first return to the root directory and then use cd /d to jump
:: Otherwise, when on the desktop, you can't directly use cd /d to jump to the root directory of the system drive
setlocal enabledelayedexpansion
for %%i in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%i:\nul (
for /f "tokens=3" %%z in ('dir /-c %%i:\') do set freesize=%%z
if not "!freesize!"=="0" (
pushd %%i:\
for /r %%k in (.) do (
if exist %%k\icon.ico echo %%k\icon.ico
)
)
)
)
popd
pause
Last edited by namejm on 2006-9-1 at 23:08 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-1 22:13 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by namejm at 2006-9-1 22:13:
全盘查找指定文件的功能,我头两天弄了一个,发出来给你借鉴一下吧。
@echo off
:: 全盘搜索指定的文件
:: 注意文件夹的跳转,要在盘符堮..
呵呵,我抄论坛有个文章的那个比这个要简单多了哦
Originally posted by namejm at 2006-9-1 22:13:
The function of searching for a specified file across the entire disk. I made one the other day, and I'll post it for your reference.
@echo off
:: Search for a specified file across the entire disk
:: Note the folder jumps, you need to jump in and out of the drive letters..
Hehe, I copied an article from the forum, and the one there is much simpler than this one oh
|
|
2006-9-3 01:37 |
|
|