windows下文件搜索

软件和网站开发以及相关技术探讨
回复
mad_frog
帖子: 55
注册时间: 2011-06-29 11:26

windows下文件搜索

#1

帖子 mad_frog » 2013-05-13 16:18

请教大家一下,用python实现
我有以下目
'''
D:\test1\2013_05\a\a.2013_05_13.tar.gz
D:\test2\2013_05\b\b.2013_05_13.tar.gz
D:\test3\2013_05\c\
'''
想做一个判断:如果目录下面存在一个以当前日期为名且后缀为tar.gz的文件,输出内容为以下:
a check ok
b check ok
c check fail
Soph
帖子: 100
注册时间: 2012-08-25 14:56

Re: windows下文件搜索

#2

帖子 Soph » 2013-05-13 17:05

以前会点Python, 现在只能用VBA了。。。
头像
lilydjwg
论坛版主
帖子: 4249
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: windows下文件搜索

#3

帖子 lilydjwg » 2013-06-16 21:41

[python]
import os
import time

basedir = 'D:/test1/2013_05/'
for i in os.listdir(basedir):
fname = '%s.%s.tar.gz' % (i, time.strftime('%Y_%m_%d'))
f = os.path.join(basedir, i, fname)
if os.path.exists(f):
st = 'ok'
else:
st = 'fail'
print('%s check %s' % (i, st))
[/python]
回复