思路:读取当前文件夹下文件名单并保存到txt,设置flag标识行数,两层循环读取文件内容
@echo off & setlocal enabledelayedexpansion //关闭所有命令回显,启动变量延迟(用!!括起变量) dir */b >filenamesThisDir.txt //保存当前目录下文件名到txt,覆盖原内容 set lineFlag=0 set OUTPUT_FILE=outputcsv.csv if exist %OUTPUT_FILE% del %OUTPUT_FILE% for /f "usebackq delims=*" %%i in ("filenamesThisDir.txt") do ( //注意双引号单引号的使用,参考/? set /a lineFlag+=1 // ‘/a'支持计算 if !lineFlag! GEQ 0 ( //greater equal set lineContent=%%i echo lineContent= !lineContent! set lineflag2=0 for /f "usebackq delims=*" %%j in ("!lineContent!") do ( set /a lineflag2+=1 if !lineflag2! ==1 ( set lineC2=%%j echo lineC2 = !lineC2! echo !lineC2! >>%OUTPUT_FILE% //将读取内容保存到目标文件,接续在文件尾 ) ) ) )
参考:
https://bbs.csdn.net/topics/392078603
https://blog.csdn.net/greenery/article/details/17146431
https://blog.csdn.net/i_likechard/article/details/79984294
https://blog.csdn.net/wsq119/article/details/116303559
http://www.bathome.net/thread-41717-1-1.html
https://baike.baidu.com/item/BAT/365230#6-8
https://blog.csdn.net/gqg_guan/article/details/123200677
https://blog.csdn.net/chuangxin/article/details/104100725
https://blog.csdn.net/HYK_DJ5201314/article/details/127985459
https://www.zhihu.com/question/587211918
https://zhuanlan.zhihu.com/p/54572985
https://www.cnblogs.com/xpwi/p/9628613.html
https://www.cnblogs.com/wengzhijie/p/11428155.html
https://www.cnblogs.com/zwk-It-goodmorning/p/14204844.html