注册 登录
编程论坛 Windows论坛

bat批量查找文件将复制其到目标文件夹代码运行异常,请各位大咖帮忙

自强不西 发布于 2023-10-12 13:55, 7789 次点击
如题,请各位大咖看看为啥双击运行后,没反应。附代码:
@echo off
set source_folder=C:\Users\xuezhaoshun\Desktop\xinjian\xj //定义源文件所在路径
set dest_folder=C:\Users\xuezhaoshun\Desktop\xinjian //定义复制后目标文件存储路径
set file_list=files.txt //需复制的文件清单
for /f % source_folder % %%a in (% file_list %) do copy "%%a" % dest_folder % //将文件清单中的文件复制到目标文件存储路径
9 回复
#2
自强不西2023-10-12 16:46
@echo off
set source_folder=C:\Users\xuezhaoshun\Desktop\xinjian\xj
set dest_folder=C:\Users\xuezhaoshun\Desktop\xinjian
set file_list=C:\Users\xuezhaoshun\Desktop\xinjian\files.txt
for /r % source_folder % %%a in ( * ) do ( xcopy %%a % dest_folder % )
pause
#3
自强不西2023-10-12 16:47
2楼的代码可以把一个文件夹中的内容复制到目标文件夹中。现在就是无法把指定的文件清单中的文件复制到目标文件夹中
#4
yiyanxiyin2023-10-12 17:30
for /r  %source_folder% %%a in (*) do ( if %%~nxa == %file_list% (copy %%a %dest_folder%))
#5
yiyanxiyin2023-10-12 17:43
for /r  %source_folder% %%a in (*%file_list%) do ( if %%~nxa == %file_list% (copy %%a %dest_folder%))
这样效率更高一点, file_list不要带路径
#6
自强不西2023-10-12 17:47
版主,还是不行,一下就闪退了,并且也没有复制清单中的文件到指定文件夹。
for /r  %source_folder% %%a in (*) do ( if %%~nxa == %file_list% (copy %%a %dest_folder%))
#7
自强不西2023-10-12 17:51
复制后代码是这样:
@echo off
set source_folder=C:\Users\xuezhaoshun\Desktop\xinjian\xj
set dest_folder=C:\Users\xuezhaoshun\Desktop\xinjian
set file_list=C:\Users\xuezhaoshun\Desktop\xinjian\files.txt
for /r  % source_folder % %%a in (*%file_list%) do ( if %%~nxa == % file_lis t% (copy "%%a" % dest_folder %))
pause
#8
yiyanxiyin2023-10-12 18:39
@echo off
set source_folder=C:\Users\xuezhaoshun\Desktop\xinjian\xj
set dest_folder=C:\Users\xuezhaoshun\Desktop\xinjian
set file_list=C:\Users\xuezhaoshun\Desktop\xinjian\files.txt
for /F "tokens=*" %%a in (%file_list%) do (copy "%source_folder%\%%a" "%dest_folder%\%%a")
pause

[此贴子已经被作者于2023-10-13 10:05编辑过]

#9
自强不西2023-10-14 10:05
版主还是不行,提示如下:
只有本站会员才能查看附件,请 登录

以下是引用yiyanxiyin在2023-10-12 18:39:25的发言:

@echo off
set source_folder=C:\Users\xuezhaoshun\Desktop\xinjian\xj
set dest_folder=C:\Users\xuezhaoshun\Desktop\xinjian
set file_list=C:\Users\xuezhaoshun\Desktop\xinjian\files.txt
for /F "tokens=*" %%a in (%file_list%) do (copy "%source_folder%\%%a" "%dest_folder%\%%a")
pause

#10
自强不西2023-10-14 13:20
感谢版主yiyanxiyin,问题已解决,具体代码如下:
@echo off
set source_folder=H:\100SSCAM
set dest_folder=C:\Users\Administrator\Desktop\xinjian
set file_list=C:\Users\Administrator\Desktop\xinjian\list.txt
for /F "tokens=*" %%a in (%file_list%) do copy "%%a" %dest_folder%
pause
1