在以下用于从目录复制最近创建的文件的批处理脚本中,我想包括和排除特定的文件名,但不确定如何。
@echo off
set source="C:FolderAFolderB"
set target="C:FolderCFolderD"
FOR /F "delims=" %%I IN ('DIR %source%*.* /A:-D /O:-D /B') DO COPY %source%"%%I" %target% & echo %%I & GOTO :END1
:END1
...
set source="C:FolderEFolderF" <--- From this directory I would also want to copy, in addition to the most recent file created, the most recent file created that has the word "error" in the file name.
set target="C:FolderCFolderD"
FOR /F "delims=" %%I IN ('DIR %source%*.* /A:-D /O:-D /B') DO COPY %source%"%%I" %target% & echo %%I & GOTO :END2
:END2
…
set source="C:FolderGFolderH" ***<---From this folder i copy the most recent created file, but would like to exclude the files that contains the word "Graphical" in the file name.***
set target="C:FolderCFolderD"
FOR /F "delims=" %%I IN ('DIR %source%*.* /A:-D /O:-D /B') DO COPY %source%"%%I" %target% & echo %%I & GOTO :END3
:END3
有人能帮我吗?:(
下面是一个可以用QUOTED参数调用的脚本For:
- Arg 1:目录切换和搜索模式
- Arg 2:Findstr要匹配的字符串
- Arg 3:条件运算符
||
或&&
执行以下命令 - Arg 4:在
Dir | Findstr
的输出上执行的初始化命令语法 - [可选]:Arg 5:要在
Dir | Findstr
的输出上执行或附加的尾随命令语法/string
@Echo Off
Set "Param3="
Set "Usage=Echo/%~n0 ^<Pattern^> ^<Match String^> ^<[^|^|]^|[^&^&]^> ^<"Command"^> [String / Command]&Echo/Args 4 or 5 can reference %%G and it's modifiers to access output.&Exit /B 0"
IF "%~4"=="" (%Usage%)
IF "%~3"=="&&" (Set Param3=_)Else IF "%~3"=="||" (Set Param3=_)
If not Defined Param3 (Echo/Invald Param for Operator ^<[^|^|]^|[^&^&]^> & %Usage%)
If Not "%~5"=="" For /F "Delims=" %%G in ('Dir %~1 ^|^| ^(Echo/Invalid Dir Options^&Exit /b 0^)')Do Echo/"%%~G" | Findstr /LIC:"%~2" > Nul 2> Nul %~3 ( %~4 %%~G %~5 2> Nul || Echo/ Error in Command Usage: "%~4" %%G "%~5" )
If "%~5"=="" For /F "Delims=" %%G in ('Dir %~1 ^|^| ^(Echo/Invalid Dir Options^&Exit /b 0^)')Do Echo/"%%~G" | Findstr /LIC:"%~2" > Nul 2> Nul %~3 ( %~4 %%~G 2> Nul || Echo/ Error in Command Usage: "%~4" %%G )
命令行中的用法示例:
C:UserstcdouDesktop $> $MATCH "/A:-D /B *.bat" "$" "&&" "Echo/[%~tG] " " [%~zG ]"
[05/09/2020 09:35 PM] $Array.bat [8940 ]
[26/09/2020 12:13 PM] $base.bat [4930 ]
[12/09/2020 04:11 PM] $Case.bat [748 ]
[23/09/2020 11:50 AM] $compare.bat [1737 ]
[12/09/2020 03:10 PM] $find.bat [334 ]
[24/09/2020 12:28 PM] $game.bat [4161 ]
[15/09/2020 02:41 AM] $Group.bat [463 ]
[26/09/2020 02:36 PM] $in.bat [511 ]
[25/09/2020 04:58 AM] $LA.bat [2098 ]
[23/09/2020 10:39 AM] $label.bat [156 ]
[26/09/2020 11:55 AM] $list.bat [1554 ]
[28/09/2020 12:48 AM] $MATCH.bat [744 ]
[23/09/2020 03:55 AM] $mc2.bat [1697 ]
[07/09/2020 01:35 AM] $nArray.bat [1581 ]
[07/09/2020 12:55 AM] $oldlost.bat [1199 ]
[12/09/2020 12:35 AM] $remstr.bat [572 ]
[12/09/2020 12:23 AM] $remstr2.bat [682 ]
[12/09/2020 03:38 AM] $RGN.bat [1277 ]
[12/09/2020 01:36 PM] $SSM.bat [850 ]
[10/09/2020 06:37 AM] $Str.bat [515 ]
[22/09/2020 01:37 AM] $VT.bat [1194 ]
[06/09/2020 11:59 PM] test$.bat [1184 ]