如何使用bat批量按文件夹名称筛选文件夹并复制到指定地方?
一个文件夹内有上千个文件夹,文件夹格式为tile_****_****,用一个txt文件夹记录需要的文件夹名比如tile_1111_1111,运行bat后,把这个txt里记...
一个文件夹内有上千个文件夹,文件夹格式为tile_****_****,用一个txt文件夹记录需要的文件夹名比如tile_1111_1111,运行bat后,把这个txt里记录的文件夹复制到一个指定的文件夹下
展开
15个回答
展开全部
不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本,另存为***.bat,编码选ANSI@echo off&cd /d "%~dp0"
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
展开全部
@echo off & title 根据列表复制文件夹到指定位置 By 依梦琴瑶
::设置文件夹列表文件
set List=FolderList.txt
::设置主源目录
set SrcFolder=D:\源目标目录
::设置指定保存目录
set SavFolder=E:\最终保存目录
for /f "delims=" %%a in ('type "%List%"') do (
if exist "%SrcFolder%\%%~a\." (
xcopy /s /e /y "%SrcFolder%\%%~a\" "%SavFolder%\%%~a\"
) else (
echo 指定的目录 "%%~a" 不存在。
)
)
pause
脚本保存编码务必设为ANSI,以免中文字符出现乱码。
::设置文件夹列表文件
set List=FolderList.txt
::设置主源目录
set SrcFolder=D:\源目标目录
::设置指定保存目录
set SavFolder=E:\最终保存目录
for /f "delims=" %%a in ('type "%List%"') do (
if exist "%SrcFolder%\%%~a\." (
xcopy /s /e /y "%SrcFolder%\%%~a\" "%SavFolder%\%%~a\"
) else (
echo 指定的目录 "%%~a" 不存在。
)
)
pause
脚本保存编码务必设为ANSI,以免中文字符出现乱码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本,另存为***.bat,编码选ANSI@echo off&cd /d "%~dp0"
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本,另存为***.bat,编码选ANSI@echo off&cd /d "%~dp0"
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本,另存为***.bat,编码选ANSI@echo off&cd /d "%~dp0"
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
rem 根据一个txt文本文件内列出的文件名称前缀字符,从一个指定目录里查找出符合条件的子文件夹并拷贝/复制到另一个指定目录里
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "oldfolder=D:\xxx\原文件夹"
set "newfolder=E:\yyy\新文件夹"
set "txtfille=***.txt"
if not exist "%oldfolder%" (echo;"%oldfolder%" 未找到&pause&exit)
if not exist "%newfolder%" md "%newfolder%"
if not exist "%txtfille%" (echo;"%txtfille%" 未找到&pause&exit)
if "%oldfolder:~-1%" equ "\" set "oldfolder=%oldfolder:~,-1%"
if "%newfolder:~-1%" equ "\" set "newfolder=%newfolder:~,-1%"
for /f "delims=" %%a in ('type "%txtfille%"') do (
for /f "delims=" %%b in ('dir /ad-h/b "%oldfolder%\%%a_*" 2^>nul') do (
echo;"%oldfolder%\%%~nxb" --^> "%newfolder%"
)
)
echo;%#% +%$%%$%/%_% %z%
pause
exit
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询