*.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
[ Last edited by he200377 on 2006-9-6 at 02:52 ]
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 ]
