如何取得一文件的生成日期及时间

ice2water 2003-01-17 09:07:10
如何取得一文件的生成日期及时间。

1.先定义结构 FILETIME
LONG dwLowDateTime
LONG dwHighDateTime
2.再定义外部函数
Function integer GetFileTime(long ll_file_handle,ref FILETIME CreateTime,ref FILETIME LastAccessTime,ref FILETIME LastWriteTime) library 'Kernel32.dll'
3.打开一个文件,将文件句柄传入该函数即可。

不知哪位大侠能给个完整的例子?
...全文
130 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyxit 2003-01-18
  • 打赏
  • 举报
回复
导入这个窗口:
$PBExportHeader$w_filetimestamp.srw
forward
global type w_filetimestamp from Window
end type
type st_2 from statictext within w_filetimestamp
end type
type sle_timestamp from singlelineedit within w_filetimestamp
end type
type st_1 from statictext within w_filetimestamp
end type
type sle_filename from singlelineedit within w_filetimestamp
end type
type cb_1 from commandbutton within w_filetimestamp
end type
end forward
type FileTime from structure
ulong dwLowDateTime
ulong dwHighDateTime
end type

type WIN32_Find_DataA from structure
long dwfileattributes
filetime ftcreationtime
filetime ftlastaccesstime
filetime ftlastwritetime
long nfilesizehigh
long nfilesizelow
long dwreserved0
long dwreserved1
char filename[260]
char alternatefilename[14]
end type

type SystemTime from structure
uint wYear
uint wMonth
uint wDayOfWeek
uint wDay
uint wHour
uint wMinute
uint wSecond
uint wMilliseconds
end type

global type w_filetimestamp from Window
int X=1056
int Y=484
int Width=2016
int Height=436
boolean TitleBar=true
string Title="Get File Timestamp"
long BackColor=78682240
boolean ControlMenu=true
boolean MinBox=true
boolean MaxBox=true
boolean Resizable=true
st_2 st_2
sle_timestamp sle_timestamp
st_1 st_1
sle_filename sle_filename
cb_1 cb_1
end type
global w_filetimestamp w_filetimestamp

type prototypes
Function ulong FindFirstFile (string lpFileName, ref WIN32_FIND_DATAA lpFindFileData) Library "KERNEL32.DLL" Alias for "FindFirstFileA"
Function boolean FileTimeToSystemTime (ref FILETIME lpFileTime, ref SYSTEMTIME lpSystemTime) Library "KERNEL32.DLL"
Function boolean FileTimeToLocalFileTime (ref FILETIME lpFileTime, ref FILETIME lpLocalFileTime) Library "KERNEL32.DLL"

end prototypes

type variables

end variables

on w_filetimestamp.create
this.st_2=create st_2
this.sle_timestamp=create sle_timestamp
this.st_1=create st_1
this.sle_filename=create sle_filename
this.cb_1=create cb_1
this.Control[]={this.st_2,&
this.sle_timestamp,&
this.st_1,&
this.sle_filename,&
this.cb_1}
end on

on w_filetimestamp.destroy
destroy(this.st_2)
destroy(this.sle_timestamp)
destroy(this.st_1)
destroy(this.sle_filename)
destroy(this.cb_1)
end on

type st_2 from statictext within w_filetimestamp
int X=78
int Y=180
int Width=677
int Height=76
boolean Enabled=false
string Text="File Modified Timestamp:"
boolean FocusRectangle=false
long TextColor=33554432
long BackColor=67108864
int TextSize=-10
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type sle_timestamp from singlelineedit within w_filetimestamp
int X=882
int Y=180
int Width=754
int Height=92
Borderstyle Borderstyle=styleLowered!
boolean AutoHScroll=false
long TextColor=33554432
long BackColor=78682240
int TextSize=-10
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type st_1 from statictext within w_filetimestamp
int X=78
int Y=84
int Width=315
int Height=76
boolean Enabled=false
string Text="Select file:"
boolean FocusRectangle=false
long TextColor=33554432
long BackColor=67108864
int TextSize=-10
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type sle_filename from singlelineedit within w_filetimestamp
int X=389
int Y=72
int Width=1248
int Height=92
int TabOrder=20
Borderstyle Borderstyle=styleLowered!
boolean AutoHScroll=false
long TextColor=33554432
int TextSize=-10
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type cb_1 from commandbutton within w_filetimestamp
int X=1678
int Y=64
int Width=251
int Height=108
int TabOrder=10
string Text="Browse"
int TextSize=-10
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

event clicked;string ls_pathname, ls_filename
WIN32_Find_DataA lfd_lpFindFileData, lfd_lpFindFileData_Local
SystemTime lst_lpSystemTime

if GetFileOpenName ("Pick Any File", ls_pathname, ls_filename) > 0 then
sle_filename.Text = ls_pathname
FindFirstFile (ls_pathname, lfd_lpFindFileData)
FileTimeToLocalFileTime(lfd_lpFindFileData.ftlastwritetime, lfd_lpFindFileData_Local.ftlastwritetime)
if FileTimeToSystemTime (lfd_lpFindFileData_Local.ftlastwritetime, lst_lpSystemTime) then
sle_timestamp.Text = string (datetime(date(lst_lpSystemTime.wyear, &
lst_lpSystemTime.wmonth, lst_lpSystemTime.wday),time(lst_lpSystemTime.whour, &
lst_lpSystemTime.wminute, lst_lpSystemTime.wsecond)), "mm/dd/yyyy hh:mm:ss")
end if
end if
end event
flyerlxg 2003-01-18
  • 打赏
  • 举报
回复
study and help you up
pbcoder 2003-01-18
  • 打赏
  • 举报
回复
学习!
myclife 2003-01-18
  • 打赏
  • 举报
回复
关注!
ice2water 2003-01-18
  • 打赏
  • 举报
回复
能给一个PB的例子吗
geomis 2003-01-17
  • 打赏
  • 举报
回复
// GetLastWriteTime - retrieves the last-write time and converts the
// time to a string
// Return value - TRUE if successful, FALSE otherwise
// hFile - must be a valid file handle
// lpszString - pointer to buffer to receive string

BOOL GetLastWriteTime(HANDLE hFile, LPSTR lpszString)
{
FILETIME ftCreate, ftAccess, ftWrite;
SYSTEMTIME stUTC, stLocal;

// Retrieve the file times for the file.
if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
return FALSE;

// Convert the last-write time to local time.
FileTimeToSystemTime(&ftWrite, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

// Build a string showing the date and time.
wsprintf(lpszString, "%02d/%02d/%d %02d:%02d",
stLocal.wDay, stLocal.wMonth, stLocal.wYear,
stLocal.wHour, stLocal.wMinute);

return TRUE;
}

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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