Get and modify files in Delphi

xiaoxiao2021-03-06  51

Time to obtain and modify files in Delphi This article describes how to use system functions and Windows API function calls to get and modify files in Delphi. Friends who are familiar with Windows 95/98 must often use the way to right-click the mouse button to view the properties information of the selected file. The creation time, modification time, and access time of the file are listed in the property menu. This information is often useful, and their settings are generally completed by the operating system (that is, DOS / Windows, etc.) without making the user easily modified. Here, I introduce you to how to achieve the acquisition and modification method of the file time in Delphi. Delphi provides a very complete call interface for Windows API functions, which can be convenient for advanced Windows programming. The detailed file time information is recorded in the Findata field in this record in the Findata domain in the record in Delphi. Unfortunately, however, the time information in the Findata cannot be directly obtained. Therefore, some people (editors are unfortunately, I don't know this person's name), write a conversion function to complete the conversion of the file time format. The following specific method is given for reference: function CovFileDate (Fd: _FileTime): TDateTime; {time file format conversion} var Tct: _SystemTime; Temp: _FileTime; begin FileTimeToLocalFileTime (Fd, Temp); FileTimeToSystemTime (Temp , TCT); COVFILEDATE: = SystemTimetodateTime (TCT); END; With the above function support, we can get a file time information. The following is a simple example: ProCDEURE GETFILETIME (Const TF: String); {Get file time, TF indicates target file path and name} const model = yyyy / mm / dd, hh: mm: ss; {Setting time format} VAR TP: TSEARCHREC; {State TP is a lookup record} T1, T2, T3: String; Begin Findfirst (TF, FAANYFILE, TP); {Find Target File} T1: = Formator, CovfileDate (tp.findata.ftcreationTime )))); {Return file creation time} T2: = formatdatetime (MODEL, COVFILEDATE (TP.FindData.ftlastWritetime))); {Return file modification time} T3: = formtdatetime (model, now)); {Return file Current access time} FindClose (TP); END; setting files to be complex, herein introduces DataTimePicker components in Delphi to assist completed this complex operation. The following example uses four DataTimePicker components to complete file creation time and modification time settings. Note: The access time of the file is replaced by modification time. When using the following example, add four DataTimePicker components on your Form.

转载请注明原文地址:https://www.9cbs.com/read-116060.html

New Post(0)