I am trying to get this bat file to copy file based on certain criteria.
我试图让这个bat文件根据某些标准复制文件。
What am I missing to get this to work?
为了让这个工作,我错过了什么?
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
set "PATTERN=*.nwd"
set "SOURCE=C:\NWD\"
set "TARGET=C:\NWM\"
set "STRING1=191058"
pushd "%SOURCE%" && (
for /F "delims=" %%F in ('findstr /S /M /I /R /C:"\<%STRING1%\>" "%PATTERN%"') do (
ECHO copy "%%F" "%TARGET%"\"%%~nxE"
)
)
popd
)
endlocal
exit /B
1 个解决方案
#1
1
To fix your code you can do this:
要修复代码,您可以执行以下操作:
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
set "PATTERN=*.nwd"
set "SOURCE=C:\NWD\"
set "TARGET=C:\NWM\"
set "STRING1=191058"
pushd "%SOURCE%" && (
for /F "delims=" %%F in ('findstr /S /M /I /R /C:"\<%STRING1%\>" "%PATTERN%"') do (
ECHO copy "%%F" "%TARGET%%%~nxF"
)
)
popd
endlocal
exit /B
I'd change it to this though:
我会改变它:
@Echo Off
Set "PATTERN=*.nwd"
Set "SOURCE=C:\NWD"
Set "TARGET=C:\NWM"
Set "STRING1=191058"
CD /D "%SOURCE%" 2>Nul || Exit /B
For /F "Delims=" %%A In ('FindStr /SM "\<%STRING1%\>" "%PATTERN%"') Do (
Echo Copy /Y "%%A" "%TARGET%\%%~nxA")
You may wish to add a pause in order to see the Echo
before the script closes
您可能希望添加暂停,以便在脚本关闭之前查看Echo
#1
1
To fix your code you can do this:
要修复代码,您可以执行以下操作:
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
set "PATTERN=*.nwd"
set "SOURCE=C:\NWD\"
set "TARGET=C:\NWM\"
set "STRING1=191058"
pushd "%SOURCE%" && (
for /F "delims=" %%F in ('findstr /S /M /I /R /C:"\<%STRING1%\>" "%PATTERN%"') do (
ECHO copy "%%F" "%TARGET%%%~nxF"
)
)
popd
endlocal
exit /B
I'd change it to this though:
我会改变它:
@Echo Off
Set "PATTERN=*.nwd"
Set "SOURCE=C:\NWD"
Set "TARGET=C:\NWM"
Set "STRING1=191058"
CD /D "%SOURCE%" 2>Nul || Exit /B
For /F "Delims=" %%A In ('FindStr /SM "\<%STRING1%\>" "%PATTERN%"') Do (
Echo Copy /Y "%%A" "%TARGET%\%%~nxA")
You may wish to add a pause in order to see the Echo
before the script closes
您可能希望添加暂停,以便在脚本关闭之前查看Echo