Python 查找变量和文本后面的所有字符

Python 查找变量和文本后面的所有字符,python,variables,Python,Variables,我有一个查找文件的代码,它获取上次保存(修改)的时间,然后将其与新时间进行比较。如果发现差异,将弹出通知 但是电子表格March.xlsx名称可以更改为(示例)电子表格March 123.xlsx,我正在寻找类似于excel的东西,在末尾添加*以便它包含电子表格路径变量后面的所有内容 import os.path, time from win10toast import ToastNotifier SpreadsheetPath = "X\Spreadsheet March.xls

我有一个查找文件的代码,它获取上次保存(修改)的时间,然后将其与新时间进行比较。如果发现差异,将弹出通知

但是电子表格March.xlsx名称可以更改为(示例)电子表格March 123.xlsx,我正在寻找类似于excel的东西,在末尾添加*以便它包含电子表格路径变量后面的所有内容

import os.path, time
from win10toast import ToastNotifier


SpreadsheetPath = "X\Spreadsheet March.xlsx"
Spreadsheet_OldTime = time.ctime(os.path.getmtime(SpreadsheetPath))

def notif(file):
    toaster = ToastNotifier()
    toaster.show_toast(file, file + " has been saved")

while True:
    print("Comparing Spreadsheet Time - " + Spreadsheet_OldTime[11:19] + " and " + time.ctime(os.path.getmtime(SpreadsheetPath))[11:19])
    if Spreadsheet_OldTime != time.ctime(os.path.getmtime(SpreadsheetPath)):
        notif("Spreadsheet")
        Spreadsheet_OldTime = time.ctime(os.path.getmtime(SpreadsheetPath))
        print("Notification Pushed")
    else:
        print("No difference found...")
        print("Sleeping for 10 seconds\n")
        time.sleep(10)
我尝试用谷歌搜索它,但不幸的是找不到一个简单易行的解决方案

您可以使用它来查找与您提供的模式匹配的路径名。从库页面:

>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']
谢谢。我用过glob

import glob
import time
import os.path

path = glob.glob('W:\Spreadsheet March*')
x = time.ctime(os.path.getmtime(*path))

print(x)

您想获取每个文件的路径,其名称的格式为
电子表格March xxxx.xlsx
?如果是,则尝试使用正则表达式