# coding=gbk
import os
import os.path
#读取目录下的所有文件,包括嵌套的文件夹
def GetFileList(dir, fileList):
newDir = dir
if os.path.isfile(dir):
fileList.append(dir)
elif os.path.isdir(dir):
for s in os.listdir(dir):
# 如果需要忽略某些文件夹,使用以下代码
# if s == "xxx":
# continue
newDir = os.path.join(dir, s)
GetFileList(newDir, fileList)
return fileList
fileDir = "E:\\Differnernt_Size_Digit_Data\\ReSize\\Train\\28x28"
list = GetFileList(fileDir, [])
# 打开一个文件
fo = open("file_list.txt", "w") # 打开文件
for i in list:
print(i) # 测试完整文件路径
print(os.path.basename(i)) # 文件名
index = i.find(".", 0) # 找到点号的位置
print(i[index - 1:index]) # 截取目标字符
print(os.path.basename(i) + " " + i[index - 1:index]) # 测试目标字符串
fo.write(os.path.basename(i) + " " + i[index - 1:index] + "\n") # 将目标字符串写入文件
fo.close() # 关闭打开的文件
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }