Fork me on Gitee

bat脚本查找指定目录下的文件并将所有文件内容合并输出到一个文件里 写软著专用提取代码

1.将下面的代码复制到 并另存为【查找文件并合并内容.bat】里

echo off & color 0A
:: 判断输入路径是不是文件夹,如果是,则获取文件夹下的所有文件名(包括子文件夹下的)
:: 如果要文件名带上路径,则需要在dir这一句的%%~nxi上作改动
if exist list.txt del list.txt /q
:input
cls
set input=:
set /p input=      请输入要进行判断的路径:
set "input=%input:"=%"
:: 上面这句为判断%input%中是否存在引号,有则剔除。
if "%input%"==":" goto input
if not exist "%input%" goto input
for %%i in ("%input%") do (
	::echo %%i >>list.txt
	if /i "%%~di"==%%i goto input
)
pushd %cd%
cd /d "%input%">nul 2>nul || exit
set cur_dir=%cd%
popd
for /f "delims=" %%i in ('dir /b /a-d /s "%input%"') do (
	::echo %%~nxi>>list.txt
	echo %cur_dir% %%i %%~nxi
	type %%i  >>  list.txt
) 
pause
if not exist list.txt goto no_file
start list.txt
exit
 
:no_file
cls
echo    %cur_dir% 文件夹下没有单独的文件
echo  ------------------------------End----------------------------------------------
pause

  2.双击文件,输入需要指定的目录,并回车,

回车后如下图,按任意键可打开合并后的list.txt文件

 

 

 如果觉得另存很麻烦,也可以直接下载

链接:https://pan.baidu.com/s/1BWwDUyTo0fAOZmMuVUzgEQ
提取码:2e6h

 

posted @ 2022-11-29 23:19  JoePotter  阅读(919)  评论(0编辑  收藏  举报
``