如何在PB中取得文件修改时间

yinoxixi 2007-12-10 02:24:27
在Windows环境中,需要定期自动删除指定路径的过期文件,请问要如何才能取得所有过期文件呢?谢谢!
...全文
382 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
都是很好的建议! 值得学习
UltraBejing 2008-04-30
  • 打赏
  • 举报
回复
lz要干嘛?
大熊猫侯佩 2007-12-14
  • 打赏
  • 举报
回复
long lul_date
long lul_time
int lui_year
int lui_month
int lui_day
int lui_hour
int lui_minute
int lui_second


你最好把上面的搞成一个结构,这样我觉得好点。
yinoxixi 2007-12-14
  • 打赏
  • 举报
回复
问题已经解决,谢谢!
现在把我的代码共享给大家:

long ll_filecount
long ll_cnt
long ll_filehandle
date ldt_today_date
date ldt_temp_file
string ls_file
string ls_full_path
string ls_directorya
string ls_filename
string ls_filename1
datetime ldt_today
datetime ldt_filedatetime
//get file time
long lul_date
long lul_time
int lui_year
int lui_month
int lui_day
int lui_hour
int lui_minute
int lui_second
s_WIN32_FIND_DATA ss_file

if fc_isnull(trim(as_file_path), "") = "" then
return 0
end if

ls_directorya = trim(as_file_path)
if right(ls_directorya, 1) = '\' then
ls_file = ls_directorya + '*.*'
else
ls_file = ls_directorya + '\*.*'
end if

if not lb_files.DirList(ls_file, 0+1+2+16+32) then
return -1
end If

ll_filecount = lb_files.TotalItems()
for ll_cnt = 1 To ll_filecount
ls_file = lb_files.Text(ll_cnt)

if left(ls_file,1) = '[' then
ls_filename = right(ls_file,len(ls_file) - 1)
ls_filename = left(ls_filename,len(ls_filename) - 1)
if ls_filename = '..' then continue
else
if right(ls_directorya, 1) = '\' then
ls_filename1 = ls_directorya + ls_file
else
ls_filename1 = ls_directorya + '\' + ls_file
end if
ll_filehandle = FindFirstFileA(ls_filename1,ss_file)
FindClose(ll_filehandle)
//get file time begin
if ll_filehandle =-1 then
setnull(ldt_filedatetime)
else
filetimetodosdatetime(ss_file.ftlastwritetime,lul_date,lul_time)
lui_day = mod(lul_date,32)
lui_month = mod(lul_date,512)/32
if lui_month = 0 then
lui_month = 1
end if
lui_year = lul_date/512+1980
lui_second = mod(lul_time,32)*2
lui_minute = mod(lul_time,2048)/32
lui_hour = (lul_time)/2048 + 8
if lui_hour >= 24 then
lui_hour = lui_hour - 24
ldt_filedatetime = datetime(relativedate(date(lui_year,lui_month,lui_day),1),time(lui_hour,lui_minute,lui_second))
else
ldt_filedatetime = datetime(date(lui_year,lui_month,lui_day),time(lui_hour,lui_minute,lui_second))
end if
end if
//get file time end
if daysafter(date(ldt_filedatetime),date(adt_file_del_dt)) > 0 then
if filedelete(ls_filename1) <> true then
return -1
end if
end if
end if
next

return 0
大熊猫侯佩 2007-12-11
  • 打赏
  • 举报
回复
同样道理使用win32 api 查找:

FindFirstFile
FindNextFile

具体使用请参考下msdn或网络吧!可以搜一大把。
yinoxixi 2007-12-11
  • 打赏
  • 举报
回复
谢谢楼上的。
但问题是,在指定路径下有未知个数的文件,我要如何取得文件个数和每个文件名呢?
大熊猫侯佩 2007-12-10
  • 打赏
  • 举报
回复
你别告诉我没法调.
大熊猫侯佩 2007-12-10
  • 打赏
  • 举报
回复
调用win32 api :GetFileTime
pptor 2007-12-10
  • 打赏
  • 举报
回复
帮顶

3,424

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧