如何使用python查找文件夹中的特定文件

时间:2016-02-25 10:11:31

标签: python

文件夹中有不同的文件,我想打印以Private Sub AnalyseCTCN_Click() Dim CT2CFN1 As Range 'CT2CFN1 is column 1 Dim CT2CFN2 As Range 'CT2CFN2 is column 2 Dim CT2CFN As Range Set CT2CFN1 = Intersect(PivotTables("PivotTableCTCN").PivotFields("CUST_TYPE").PivotItems("2").DataRange.EntireRow, _ PivotTables("PivotTableCTCN").PivotFields("CUST_FULL_NAME_1").DataRange) Set CT2CFN2 = Intersect(PivotTables("PivotTableCTCN").PivotFields("CUST_TYPE").PivotItems("2").DataRange.EntireRow, _ PivotTables("PivotTableCTCN").PivotFields("CUST_FULL_NAME_2").DataRange) Set CT2CFN = Union(CT2CFN1, CT2CFN2) Dim d As Range Dim c As Range For Each d In CT2CFN1 For Each c In CT2CFN2 If InStr(1, d, "T/A", 1) = 0 And InStr(1, c, "T/A", 1) = 0 Then d.Interior.Color = RGB(255, 0, 0) End If Next c Next d End Sub 结尾的文件。这项工作的正确答案如下所示:

IHDRT.exr

2 个答案:

答案 0 :(得分:2)

#!/usr/bin/env python
import glob

for file in glob.glob("*.exr"):
    if file.endswith('iHDRT.exr'):
            ^^^^^^^^
        print(file)

endswith而非endswidth

答案 1 :(得分:1)

使用结尾,而不是结束宽度!拼写错误