import os
'''
获取文件夹目录名
'''
def GetReadDirMenu(path):
if (os.path.exists(path)):
result=[]
for i in os.listdir(path):
m = os.path.join(path,i)
if os.path.isdir(m):
result.append(i)
return result
return None
'''
获取某文件夹下的所有文件
'''
def GetReadFileMenuInList(path):
if (os.path.exists(path)):
result=[]
for i in os.listdir(path):
m = os.path.join(path,i)
if os.path.isdir(m) is False:
result.append(i)
return result
return None
'''
获取某个文件的内容
'''
def read(path):
with open(path,"r",encoding='utf-8') as f:
return f.read()
def readLines(path,hint):
with open(path,"r",encoding='utf-8') as f:
return f.readlines(hint)
def readLine(path,limit):
with open(path,"r",encoding='utf-8') as f:
return f.readline(limit)
'''
将内容写入文件
'''
def write(path):
with open(path,"w",encoding='utf-8') as f:
return f.write(path)
'''
文件替换
'''
if __name__=="__main__":
print(GetReadFileMenuInList(r"D:\Users\EX-ZHAOHUI008\PycharmProjects\testdir"))