main.bat
1 @echo off 2 color 0a 3 title Copy Files Blurry 1.0 4 pushd "%~dp0" 5 6 SETLOCAL ENABLEEXTENSIONS 7 SETLOCAL ENABLEDELAYEDEXPANSION 8 9 set CPB_T1=%TEMP%\cpb1.tmp 10 set CPB_T2=%TEMP%\cpb2.tmp 11 set CPB_T3=%TEMP%\cpb3.tmp 12 13 :PROC_MAIN 14 cd . > "%CPB_T1%" 15 echo. Note: Source folder can‘t include quotes, can‘t use the form ‘X:Y‘. Root directory ends with a backslash. The correct way of writing, such as: ‘X:\Packages‘. 16 :ENTER_SOURCE 17 set SOURCE= 18 set /p SOURCE=Source folder: 19 if "%SOURCE%" neq "" ( 20 >> "%CPB_T1%" echo %SOURCE% 21 ) else ( 22 choice /c Yn /cs /m "End input" 23 if !ERRORLEVEL! equ 1 ( 24 goto :PROC_SOURCE 25 ) 26 ) 27 goto :ENTER_SOURCE 28 29 :PROC_SOURCE 30 cd . > "%CPB_T2%" 31 for /f "usebackq tokens=*" %%i in ("%CPB_T1%") do ( 32 pushd %%i && ( 33 >> "%CPB_T2%" echo !cd! 34 popd 35 ) 36 ) 37 38 for /f %%i in ("%CPB_T2%") do ( 39 cls 40 if %%~zi equ 0 ( 41 echo. Incorrect input, please re-enter. 42 call :FN_BLOCKING 43 goto :PROC_MAIN 44 ) 45 ) 46 47 :ENTER_DESTINATION 48 set DESTINATION= 49 set /p DESTINATION=Destination folder: 50 if "%DESTINATION%" equ "" ( 51 call :FN_BLOCKING 52 goto :ENTER_DESTINATION 53 ) 54 pushd %DESTINATION% || ( 55 cls 56 echo. Invalid destination folder. 57 call :FN_BLOCKING 58 goto :ENTER_DESTINATION 59 ) 60 popd 61 cls 62 63 :ENTER_KEYWORDS 64 echo. Note: Keywords separated by spaces, such as: ‘cmake zlib-devel openssl-devel‘. 65 set KEYWORDS= 66 set /p KEYWORDS=Keywords: 67 if "%KEYWORDS%" equ "" ( 68 call :FN_BLOCKING 69 goto :ENTER_KEYWORDS 70 ) 71 echo KEYWORDS[%KEYWORDS%] 72 cd . > "%CPB_T3%" 73 call :PROC_KEYWORDS %KEYWORDS% 74 for /f %%i in ("%CPB_T3%") do ( 75 cls 76 if %%~zi equ 0 ( 77 echo. Invalid keywords. 78 call :FN_BLOCKING 79 goto :ENTER_KEYWORDS 80 ) 81 ) 82 83 echo. Note: The following files will be copied to the destination. 84 echo %DESTINATION% 85 echo. 86 for /f "usebackq tokens=*" %%i in ("%CPB_T2%") do ( 87 echo ^<%%i^> 88 for /f "usebackq tokens=*" %%x in ("%CPB_T3%") do ( 89 echo ^|-- *%%x* 90 ) 91 ) 92 echo. Note: it will overwrite the files already stored in the destination. 93 choice /c Yn /cs /m "Are you sure?" 94 cls 95 if %ERRORLEVEL% equ 2 ( 96 goto :ENTER_KEYWORDS 97 ) 98 99 for /f "usebackq tokens=*" %%i in ("%CPB_T2%") do ( 100 for /f "usebackq tokens=*" %%x in ("%CPB_T3%") do ( 101 copy /y "%%i\*%%x*" "%DESTINATION%\" 102 ) 103 ) 104 echo. 105 echo Completed. 106 echo. 107 choice /c Yn /cs /m "Come again?" 108 if %ERRORLEVEL% equ 1 ( 109 cls 110 goto :ENTER_KEYWORDS 111 ) 112 del "%CPB_T1%" "%CPB_T2%" "%CPB_T3%" 113 exit 114 115 116 :PROC_KEYWORDS 117 if %1a==a goto :EOF 118 >> "%CPB_T3%" echo %1 119 shift 120 goto :PROC_KEYWORDS 121 122 123 @rem ##############################FBP Begin 124 @title Function Batch Program 1.0 125 @color 0a 126 @echo Note: I can‘t run independently. 127 @ping /n 3 127.0.0.1 > nul 128 @exit 129 130 rem eg. call :FN_BLOCKING 131 :FN_BLOCKING 132 choice /t 1 /c O /cs /d O /n 133 cls 134 goto :EOF 135 @rem ##############################FBP End
原文地址:https://www.cnblogs.com/rms365/p/11148531.html
时间: 2024-10-10 04:34:42