如何遍历一文件夹下所有文件

如何遍历一文件夹下所有文件,第1张

这是一个递归调用的做法。 你可以做个函数 findAll 参数是 目录名 。 开始遍历,当你发现当前是目录。应该再调用函数findall,传入目录,让函数去遍历子目录。这样函数返回后,你可以继续遍历。

import glob

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)

您好,很高兴能帮助您

Private Sub Command1_Click()

Dim FileName As String, FilePath As String

Dim iFolder As Object, Xlapp As Object, Sh As Object

Set iFolder = CreateObject("shell.application").BrowseForFolder(0, "", 0, "")

If iFolder Is Nothing Then Exit Sub

FilePath = iFolder.Items.Item.Path

FilePath = IIf(Right(FilePath, 1) = "\", FilePath, FilePath &"\")

FileName = Dir(FilePath &"*.xls*")

Set Xlapp = CreateObject("excel.application")

Xlapp.displayalerts = False

Do Until Len(FileName) = 0

With Xlapp.workbooks.open(FilePath &FileName)

For Each Sh In .WORKSHEETS

If Len(Sh.RANGE("B2").Value) = 0 Then Sh.Delete

Next

.Close True

End With

FileName = Dir

Loop

Xlapp.quit

Set Xlapp = Nothing

End Sub

你的采纳是我前进的动力,

记得好评和采纳,答题不易,互相帮助,


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/8091509.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-13
下一篇2023-04-13

发表评论

登录后才能评论

评论列表(0条)

    保存