python 如何判断文件夹为空文件夹??求可执行代码

work_path = '你的目录'if not os.listdir(work_path): print '目录为空'如果解决了您的问题请采纳!如果未解决请继续追问
python 如何判断文件夹为空文件夹??求可执行代码
work_path = '你的目录'if not os.listdir(work_path): print '目录为空'如果解决了您的问题请采纳!如果未解决请继续追问
2015-03-12
1、def del_file_items(spath):
import os
paths = os.listdir(spath)
for pa in paths:
filepath = os.path.join(spath,pa)
if os.path.isfile(filepath):
try:
2、os.remove(filepath)
except os.error:
print "remove %s error." %filePath
elif os.path.isdir(filepath):
try:
3、##在方法内可以引用自身
del_file_items(filepath)
except os.error:
print "remove %s
2018-03-30
#coding=utf-8
import os
import os.path

#定义文件夹路径
folderpath='d:\\pvs'

#设置文件夹内容是否为空标识符
empty=False

#os.path.exists(folderpath.encode('GBK'))路径如果存在,返回True
if(os.path.exists(folderpath.encode('GBK'))==False):
#文件夹不存在时
#doing something...
else:
for root,dirs, files in os.walk(folderpath.encode('GBK')):
if(len(files)==0):
empty=True
if(empty):
#文件夹内容为空
#doing something...2015-03-12
mengvlog 阅读 10 次 更新于 2025-07-19 08:01:13 我来答关注问题0
檬味博客在线解答立即免费咨询

Python相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部