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-06-20 03:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Find Files and Operate (View Path, Copy, Delete).bat (9.5 Update) View 7,684 Replies 23
Original Poster Posted 2006-08-31 14:02 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
*.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 ]
Floor 2 Posted 2006-08-31 14:55 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-08-31 15:13 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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 ]
Floor 4 Posted 2006-08-31 17:14 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2006-08-31 17:22 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-08-31 18:11 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Thanks, I'll go back and take another look
Floor 7 Posted 2006-09-01 13:23 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Make a mark

Because it uses call: label parameter
Attachments
做恢复删除的时候想到的.rar (871 bytes, Credits to download 1 pts, Downloads: 62)
Floor 8 Posted 2006-09-01 17:17 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 9 Posted 2006-09-01 17:18 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 10 Posted 2006-09-01 17:29 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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 ]
Floor 11 Posted 2006-09-01 17:31 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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
Floor 12 Posted 2006-09-01 17:39 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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 ]
Floor 13 Posted 2006-09-01 22:09 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 14 Posted 2006-09-01 22:13 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 15 Posted 2006-09-03 01:37 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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
Forum Jump: