Batch import file names to Excel sheet

Sometimes we will encounter the need to [extract all file names under a certain folder and put them into an Excel]. It is fine if the number of files is small, but what if there are 100 or 1000? The efficiency of manual operation will be very low. You must also want to have a convenient and quick method to realize one-click batch extraction. Today, it is here!

1. First, create a txt file under the folder that needs to be extracted

It can be named batch extraction file name.txt, the content is as follows:

@ECHO OFF
DIR *.* /B> list.xls
pause

insert image description here

2. Rename the file suffix to bat

insert image description here

3. Put the .bat file in the folder to be extracted, and double-click to execute

After execution, you will see an interface like this:
insert image description here
and a new file named list.xls will be generated under the folder:
insert image description here
double-click to open list.xls, you can see that the extraction has been successful, the effect is as follows:
insert image description here

4. Remove the file suffix in Excel

If you don't want to keep the suffix in the file name extracted from Excel, you can do this:
select the file name column in WPS, and then click Data-Column-Smart Column in the upper toolbar to automatically split the data into Two columns:
insert image description here
so the first column is the file name without suffix:
insert image description here

5. Extract the file name into a txt file

If you don't want to extract the file to Excel, but want to extract it into a txt file, you can write this in the bat file:

@ECHO OFF
DIR *.* /B> list.txt
pause

The extracted results will be stored in the txt file:
insert image description here

Finally: share a filename extraction script I wrote

:: 请注意,本文件编码需为ANSI,否则运行后会乱码
@ECHO OFF
:: 预处理,删除可能存在的list.xls文件
DEL if exist list.xls
:: 打印个提示信息
echo 提示:正在提取文件名...
echo\
:: 提取文件名列表
DIR *.* /B /N> list.xls
:: 打印个提示信息
echo 提示:提取完毕,请查看list.xls文件
echo\
pause

测试开发工程师一只,也在不断的学习阶段,平时的小经验不定期分享。
希望看我写的文字的人,可以少走弯路 祝工作学习顺利。
博主经验有限,若有不足,欢迎交流,共同改进~
愿与同在CSDN的你共同进步。

Guess you like

Origin blog.csdn.net/qq_36396763/article/details/131917181