Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何编写批处理文件以查找文件并复制名称然后显示?_Windows_Batch File - Fatal编程技术网

Windows 如何编写批处理文件以查找文件并复制名称然后显示?

Windows 如何编写批处理文件以查找文件并复制名称然后显示?,windows,batch-file,Windows,Batch File,我想找到一个名为~test.c的特定文件。例如,有如下文件名: main.c 2019_test.c setting.c 然后我想复制文件名2019_test.c然后echo,它应该通过使用批处理文件(批处理脚本)工作。怎么做 我写了这段代码,但是被卡住了。它不起作用 @echo off setlocal enabledelayedexpansion for /f "delims=" %%a in ('findstr /i "_test"') do echo %%a

我想找到一个名为
~test.c
的特定文件。例如,有如下文件名:

main.c  
2019_test.c  
setting.c      
然后我想复制文件名
2019_test.c
然后echo,它应该通过使用批处理文件(批处理脚本)工作。怎么做

我写了这段代码,但是被卡住了。它不起作用

@echo off  
setlocal enabledelayedexpansion  
for /f "delims=" %%a in ('findstr /i "_test"') do echo %%a  
pause

对于(*\u test.c)中的%%a,执行echo%%a
以确保您正在检查所有文件名,包括
dir
可能有用<代码>对于/F“EOL=|Delims=“%%”In('Dir/B/S/A-D“\*.\u test.c”2^>num^ FindStr/I“\.c$”)执行@Echo%%或者,您可以使用
where.exe
代替,
用于/F“EOL=”In('where/R\“*.\u test.c”2^>num。这些示例将只在一个(当前)驱动器内搜索,因此在多个驱动器内搜索时需要扩展代码。@谢谢,这非常有用。
对于(*u test.c)中的%%a,请执行echo%%a
,以确保您正在检查所有文件名,包括
dir
<代码>对于/F“EOL=|Delims=“%%”In('Dir/B/S/A-D“\*.\u test.c”2^>num^ FindStr/I“\.c$”)执行@Echo%%
或者,您可以使用
where.exe
代替,
用于/F“EOL=”In('where/R\“*.\u test.c”2^>num。这些示例将只在一个(当前)驱动器内搜索,因此在多个驱动器内搜索时需要扩展代码。@Compo谢谢,这非常有用。