cmd看excel有多少个子表,获取以CMD表格式的文件列表

这篇博客介绍了如何使用批处理命令将文件列表从目录中导出,并以逗号分隔值(CSV)格式保存,以便于在Excel中打开。作者提到了两种方法,一种是使用简单的FOR循环,另一种是结合DIR和FOR/F命令,同时考虑了文件名可能包含特殊字符的情况。通过这些方法,文件名可以按名称排序并写入一行,用制表符作为分隔符。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Could you please help me to get list of files to table format (I prefer batch file). For list command I would use dir /b /o:n to sort files by name.. but this produces paragraphs. I need to copy the list of files to xls table... and the files will be in columns. So my ask is this:

If you have files like 1,2,3,4,5... etc I want them to be written on one line, where tabulator is used as separator between files.

解决方案

"Where tabulator (?) is used as separator" ??? If you want to open the file with Excel, then the simplest option is to use commas as a delimiter (.CSV format). Since a comma can appear in a file name, you want to enclose the names in quotes.

If you are sorting by name, then a simple FOR is your most efficient option, since it always sorts by name. You can use

@echo off

for %%F in (*) do set /p =""%%F","

) >fileList.csv

If you really want to use the DIR command, then you need FOR /F. The only reason I can see to do so is if you want to change the sort order. I set EOL=: to guard against the unlikely possibility of a file name starting with a semicolon. A valid file name (or file path) can never start with a colon.

@echo off

for /f "eol=: delims=" %%F in ('dir /b /o:n') do set /p =""%%F","

) >fileList.csv

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值