import os
path='C:/Users/谈仔罩EDZ/Desktop/工作/戚灶2021.08.19/'
for infile in glob.glob(os.path.join(path, '含闹*.csv')):
print(infile)
import os
import glob
path='C:/Users/EDZ/Desktop/工作/2021.08.19/'
for infile in glob.glob(os.path.join(path, '*.csv')):
os.remove(infile)
print(infile)
用dir 命令带/s参数能遍慎山历某目录里所有文件
如下例dir d:\tools /s
如文件太多慎磨查看不便你可以用dir d:\tools /s >d:\dir.txt
打开dir.txt
你要的是宽孝中不是这个
public void traverseFolder2(String path) {
File file = new File(path)
if (file.exists()) {
File[] files = file.listFiles()
if (null == files || files.length == 0) {
System.out.println("文件夹是空的!")
return
} else {
for (File file2 : files) {
if (file2.isDirectory()) {
System.out.println("文件夹:" + file2.getAbsolutePath())
traverseFolder2(file2.getAbsolutePath())
} else {
System.out.println("文件:" + file2.getAbsolutePath())
}
}
}
} else {
System.out.println("文件不存在!")
}
}
扩展资戚举料
public void traverseFolder1(String path) {
int fileNum = 0, folderNum = 0
File file = new File(path)
if (file.exists()) {
LinkedList<File>list = new LinkedList<File>()
File[] files = file.listFiles()
for (File file2 : files) {
if (file2.isDirectory()) {
System.out.println("文件夹:" + file2.getAbsolutePath())
list.add(file2)
foldeNum++
} else {
System.out.println("文件:" + file2.getAbsolutePath())
fileNum++
}
}
File temp_file
while (!list.isEmpty()) {
temp_file = list.removeFirst()
files = temp_file.listFiles()
for (File file2 : files) {
if (file2.isDirectory()) {
System.out.println("文件夹:" + file2.getAbsolutePath())
list.add(file2)
folderNum++
} else {
System.out.println("文件:" + file2.getAbsolutePath())
fileNum++
}
}
}
} else {
System.out.println("文件不存在!")
}
System.out.println("文件夹共有:" + folderNum + ",文件共笑仔桥有:"碰猛 + fileNum)
}
参考资料:百度百科 Java
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)