py:操作本目录文件时候避开子目录

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
import os
from stat import *



list1 = os.listdir(os.getcwd())
print(list1)

for file in list1:
	mode = os.stat(os.path.abspath(file)).st_mode
	if S_ISDIR(mode):
		# It's a directory, recurse into it
		print(">>>>>we have a dir")
	else:
		with open(file, 'r') as f:
			print(f.name)

在这里插入图片描述

发布了216 篇原创文章 · 获赞 33 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/paulkg12/article/details/104817324
今日推荐