pb9获取文件创建时间、最后修改时间及设置最后修改时间的方法

    将以下内容保存为本地文件n_cst_filetime.sru,然后导入pbl中

$PBExportHeader$n_cst_filetime.sru
$PBExportComments$与文件时间有关的外部函数
forward
global type n_cst_filetime from nonvisualobject
end type
type os_filedatetime from structure within n_cst_filetime
end type
type os_fileopeninfo from structure within n_cst_filetime
end type
type os_finddata from structure within n_cst_filetime
end type
type os_securityattributes from structure within n_cst_filetime
end type
type os_systemtime from structure within n_cst_filetime
end type
end forward

type os_filedatetime from structure
    unsignedlong        ul_lowdatetime
    unsignedlong        ul_highdatetime
end type

type os_fileopeninfo from structure
    character        c_length
    character        c_fixed_disk
    unsignedinteger        ui_dos_error
    unsignedinteger        ui_na1
    unsignedinteger        ui_na2
    character        c_pathname[128]
end type

type os_finddata from structure
    unsignedlong        ul_fileattributes
    os_filedatetime        str_creationtime
    os_filedatetime        str_lastaccesstime
    os_filedatetime        str_lastwritetime
    unsignedlong        ul_filesizehigh
    unsignedlong        ul_filesizelow
    unsignedlong        ul_reserved0
    unsignedlong        ul_reserved1
    character        ch_filename[260]
    character        ch_alternatefilename[14]
end type

type os_securityattributes from structure
    unsignedlong        ul_length
    string        ch_description
    boolean        b_inherit
end type

type os_systemtime from structure
    unsignedinteger        ui_wyear
    unsignedinteger        ui_wmonth
    unsignedinteger        ui_wdayofweek
    unsignedinteger        ui_wday
    unsignedinteger        ui_whour
    unsignedinteger        ui_wminute
    unsignedinteger        ui_wsecond
    unsignedinteger        ui_wmilliseconds
end type

global type n_cst_filetime from nonvisualobject autoinstantiate
end type

type prototypes
//获得应用程序名用
//Function uint GetModuleFileNameA(ulong hModule,ref string lpFilename,ulong nSize) Library "kernel32.dll" //获取应用程序运行目录

//文件操作
Function long FindFirstFileA (ref string filename, ref os_finddata findfiledata) library "kernel32.dll"
Function boolean FindNextFileA (long handle, ref os_finddata findfiledata) library "kernel32.dll"
Function boolean FindClose (long handle) library "kernel32.dll"
Function long    OpenFile (ref string filename, ref os_fileopeninfo of_struct, ulong action) LIBRARY "kernel32.dll"
Function boolean CloseHandle (long file_hand) LIBRARY "kernel32.dll"
Function boolean GetFileTime(long hFile, ref os_filedatetime  lpCreationTime, ref os_filedatetime  lpLastAccessTime, ref os_filedatetime  lpLastWriteTime  )  library "kernel32.dll"
Function boolean FileTimeToSystemTime(ref os_filedatetime lpFileTime, ref os_systemtime lpSystemTime) library "kernel32.dll"
Function boolean FileTimeToLocalFileTime(ref os_filedatetime lpFileTime, ref os_filedatetime lpLocalFileTime) library "kernel32.dll"
Function boolean SetFileTime(long hFile, os_filedatetime  lpCreationTime, os_filedatetime  lpLastAccessTime, os_filedatetime  lpLastWriteTime  )  library "kernel32.dll"
Function boolean SystemTimeToFileTime(os_systemtime lpSystemTime, ref os_filedatetime lpFileTime) library "kernel32.dll"
Function boolean LocalFileTimeToFileTime(ref os_filedatetime lpLocalFileTime, ref os_filedatetime lpFileTime) library "kernel32.dll"

end prototypes

type variables

end variables

forward prototypes
public function integer of_getcreatedatetime (string as_filename, ref datetime adt)
public function integer of_getlastwritedatetime (string as_filename, ref datetime adt)
public function integer of_setlastwritedatetime (string as_filename, datetime adt)
private function integer of_convertfiledatetimetopb (os_filedatetime astr_filetime, ref datetime adt)
private function integer of_convertpbdatetimetofile (datetime adt, ref os_filedatetime astr_filetime)
end prototypes

public function integer of_getcreatedatetime (string as_filename, ref datetime adt);//得到文件创建的时间
long ll_handle
os_finddata    lstr_FindData

// Get the file information
ll_handle = FindFirstFileA(as_FileName, lstr_FindData)
If ll_handle <= 0 Then Return -1
FindClose(ll_handle)

// Convert the date and time
Return of_ConvertFileDatetimeToPB(lstr_FindData.str_CreationTime, adt)
end function

public function integer of_getlastwritedatetime (string as_filename, ref datetime adt);//得到文件最后修改的时间
long    ll_handle
os_finddata    lstr_FindData

// Get the file information
ll_handle = FindFirstFileA(as_FileName, lstr_FindData)
If ll_handle <= 0 Then Return -1
FindClose(ll_handle)

// Convert the date and time
Return of_ConvertFileDatetimeToPB(lstr_FindData.str_LastWriteTime, adt)
end function

public function integer of_setlastwritedatetime (string as_filename, datetime adt);//设置文件最后修改时间
boolean lb_Ret
long ll_handle
os_filedatetime lstr_FileTime, lstr_Empty
os_finddata lstr_FindData
os_fileopeninfo lstr_FileInfo

// Get the file information.
// This is required to keep the Last Access date from changing.
// It will be changed by the OpenFile function.
ll_handle = FindFirstFileA(as_FileName, lstr_FindData)
If ll_handle <= 0 Then Return -1
FindClose(ll_handle)

// Convert the date and time
If of_ConvertPBDatetimeToFile(adt, lstr_FileTime) < 0 Then Return -1

// Set the file structure information
lstr_FileInfo.c_fixed_disk = "~000"
lstr_FileInfo.c_pathname = as_FileName
lstr_FileInfo.c_length = "~142"

// Open the file
ll_handle = OpenFile ( as_filename, lstr_FileInfo, 2 ) 
If ll_handle < 1 Then Return -1
 
lb_Ret = SetFileTime(ll_handle, lstr_Empty, lstr_FindData.str_LastAccessTime, lstr_FileTime)

CloseHandle(ll_handle)

If lb_Ret Then
    Return 1
Else
    Return -1
End If

end function

private function integer of_convertfiledatetimetopb (os_filedatetime astr_filetime, ref datetime adt);//转换文件系统时间为PB时间
os_filedatetime    lstr_LocalTime
os_systemtime    lstr_SystemTime

If Not FileTimeToLocalFileTime(astr_FileTime, lstr_LocalTime) Then Return -1

If Not FileTimeToSystemTime(lstr_LocalTime, lstr_SystemTime) Then Return -1

adt = datetime(blob(String(lstr_SystemTime.ui_wyear) + "-" + &
             String(lstr_SystemTime.ui_WMonth) + "-" + &
             String(lstr_SystemTime.ui_WDay) + ' ' + &
             String(lstr_SystemTime.ui_wHour) + ":" + &
             String(lstr_SystemTime.ui_wMinute) + ":" + &
             String(lstr_SystemTime.ui_wSecond) + ":" + &
             String(lstr_SystemTime.ui_wMilliseconds)))
Return 1
end function

private function integer of_convertpbdatetimetofile (datetime adt, ref os_filedatetime astr_filetime);//转换文件系统时间为PB时间
os_filedatetime    lstr_LocalTime
os_systemtime    lstr_SystemTime

lstr_SystemTime.ui_wyear = year(date(adt))
lstr_SystemTime.ui_WMonth = Month(date(adt))
lstr_SystemTime.ui_WDay = Day(date(adt))

lstr_SystemTime.ui_wHour = hour(time(adt))
lstr_SystemTime.ui_wMinute = Minute(time(adt))
lstr_SystemTime.ui_wSecond = Second(time(adt))
lstr_SystemTime.ui_wMilliseconds = Long(String(adt, "fff"))

If Not SystemTimeToFileTime(lstr_SystemTime, lstr_LocalTime) Then Return -1

If Not LocalFileTimeToFileTime(lstr_LocalTime, astr_FileTime) Then Return -1

Return 1
end function

on n_cst_filetime.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_filetime.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

程序中这样调用即可:
n_cst_filetime ln
string ls_file = 'C:\Program Files\Sybase\PowerBuilder 9.0\pb90.exe'
datetime ldt_create, ldt_lastwrite
ln.of_getcreatedatetime( ls_file, ldt_create)
ln.of_getlastwritedatetime( ls_file, ldt_lastwrite)
messagebox('提示', '文件【' + ls_file + '】~r~n~r~n创建时间:  ' + string(ldt_create, 'yyyy年mm月dd日, hh:mm:ss.fff') +&
                            '~r~n修改日期:  ' + string(ldt_lastwrite, 'yyyy年mm月dd日, hh:mm:ss.fff') )


  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
将TensorFlow的pb模型转换为Keras的h5模型,可以使用以下步骤: 1. 安装TensorFlow和Keras 2. 加载pb模型 ```python import tensorflow as tf # 加载pb模型 with tf.gfile.GFile('path/to/model.pb', 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) with tf.Session() as sess: # 将模型导入到当前图中 tf.import_graph_def(graph_def, name='') # 从当前图中获取输入和输出的张量 inputs = sess.graph.get_tensor_by_name('input_tensor_name:0') outputs = sess.graph.get_tensor_by_name('output_tensor_name:0') ``` 注意:`input_tensor_name` 和 `output_tensor_name` 需要根据你的模型来进行修改。 3. 使用Keras的函数式API创建模型 ```python from keras.layers import Input, Dense from keras.models import Model # 创建输入层 input_layer = Input(shape=(input_shape,)) # 创建中间层 hidden_layer = Dense(units=hidden_units, activation='relu')(input_layer) # 创建输出层 output_layer = Dense(units=output_units, activation='softmax')(hidden_layer) # 创建模型 model = Model(inputs=input_layer, outputs=output_layer) ``` 其中,`input_shape` 和 `output_units` 需要根据你的模型来进行修改。 4. 将权重从pb模型中加载到Keras模型中 ```python import numpy as np with tf.Session() as sess: # 将模型导入到当前图中 tf.import_graph_def(graph_def, name='') # 从当前图中获取每一层的权重和偏置 weights = {} for op in sess.graph.get_operations(): for output in op.outputs: tensor = sess.graph.get_tensor_by_name(output.name) if tensor.dtype == tf.float32.as_datatype_enum: weights[output.name] = np.array(sess.run(tensor)) # 将权重加载到Keras模型中 for layer in model.layers: if layer.name in weights: layer.set_weights(weights[layer.name]) ``` 5. 保存Keras模型为h5文件 ```python model.save('path/to/model.h5') ``` 可以使用以下代码加载h5模型并进行测试: ```python from keras.models import load_model # 加载h5模型 model = load_model('path/to/model.h5') # 进行测试 output = model.predict(np.zeros((1, input_shape))) print(output) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值