程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python extracts the name of the file in the file and imports it into Excel

編輯:Python

Program code :

import pandas as pd
import os
print(' Picture name extraction in progress ......')
imgPath=os.getcwd()
nameList=os.listdir()
for i in range(len(nameList)):
nameList[i]=os.path.splitext(nameList[i])[0]
df=pd.DataFrame(nameList)
df.to_excel(imgPath+'/A.xlsx')
print(' Picture name extraction completed !')
print('Excel The file saving path is :'+imgPath+'/A.xlsx')
os.system('pause')

If you need to package it into exe File format , You have to go through pyinstaller Tools :
1、 stay cmd Window type

pip install pyinstaller

2、 install pyinstaller After completion , Enter... Directly in the address field of the target folder cmd, stay cmd Window type

pyinstaller -F a.py #-F And then python File name of the file 

Can finish exe File generation .

such , Only need to exe Copy the file to the folder to be extracted , double-click exe file , You can extract all file names in the folder , And save the extracted file name to Excel In file .

It should be noted that : Because we put exe Files are also copied to this folder , So the extracted file name contains the exe File name of the file , stay Excel Delete from .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved