简体   繁体   中英

python is showing a excel file that is not present in a folder

Basically i'm trying to print all excel files in a directory. In one of the folders, i don't have a excel file named '~$EndManifold-4Slot.xlsm', but while printing the files, i see this is present, which is actually not there.

Could anyone suggest on how to improve the same?

        def Fnfolders(rootdir):
            xlFilesList=[]
            for dirname, dirnames, filenames in os.walk(rootdir):
                for file in os.listdir(dirname):
                    if '.xls' in file or '.xlsx' in file:
                        fullPath=os.path.join(dirname)+"\\"+file
                        xlFilesList.append(fullPath)
            return xlFilesList

        xlFilesList=Fnfolders(rootdir)
        for excel in xlFilesList:
            print (excel)

Normally, files like - ~$EndManifold-4Slot.xlsm are temporary files created when you openned your file in Excel. they are usually hidden, you can find them in your explorer if you enable Show Hidden Files in folder options.

You can read more about those temporary files here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM