Python searching directory, list basename of file, no extension

后端 未结 3 608
广开言路
广开言路 2021-01-25 05:45

I was wondering if there was anyway I could modify my code to only post the basename of the file, instead of the entire file including the extension.. I\'m new to python, so I d

3条回答
  •  悲哀的现实
    2021-01-25 06:39

    Simply in one line..., returns the found files without any file extension, for the files found in the given search directory with the requested file extension...!

    Found_BaseFile_Names= [(f.split('.'))[0] for f in os.listdir(SearchDir) if f.endswith('.txt')]
    

提交回复
热议问题