Change folder time

Source: Internet
Author: User
Tags filetime

Unit unit1; <br/> interface <br/> uses <br/> Windows, messages, sysutils, variants, classes, graphics, controls, forms, <br/> dialogs, comctrls, stdctrls; <br/> type <br/> tform1 = Class (tform) <br/> datetimepicker1: tdatetimepicker; <br/> datetimepicker2: tdatetimepicker; <br/> datetimepicker3: tdatetimepicker; <br/> datetimepicker4: tdatetimepicker; <br/> button1: tbutton; <br/> label1: tlabel; <br/> label2: tlabel; <br/> opendialog1: topendialog; <br/> edit1: tedit; <br/> button2: tbutton; <br/> procedure button1click (Sender: tobject ); <br/> procedure button2click (Sender: tobject ); <br/> private <br/> {private Declarations} <br/> Public <br/> {public declarations} <br/> end; <br/> var <br/> form1: tform1; <br/> Implementation <br/> {$ R *. DFM} <br/> function covfiledate (FD: _ filetime): tdatetime; // time format of the converted file <br/> var <br/> TCT: _ systemtime; <br/> temp: _ filetime; <br/> begin <br/> filetimetolocalfiletime (FD, temp); <br/> filetimetosystemtime (temp, TCT ); <br/> covfiledate: = systemtimetodatetime (TCT); <br/> end; <br/> procedure getfiletime (const TF: string); // get the file time, input value indicates the path of the target file <br/> const <br/> model = 'yyyy/MM/DD, HH: mm: ss '; // This is the time format <br/> var <br/> TP: tsearchrec; // declare a search record <br/> T1, T2, T3: string; <br/> begin <br/> findfirst (TF, faanyfile, TP); // search for the target file <br/> T1: = formatdatetime (model, covfiledate (TP. finddata. ftcreationtime); // returns the file creation time <br/> T2: = formatdatetime (model, covfiledate (TP. finddata. ftlastwritetime); // The modification time of the returned file <br/> T3: = formatdatetime (model, now ); // The current access time of the returned file <br/> findclose (TP); <br/> end; <br/> procedure setfiledatetime (const TF: string ); // set the file time. The input value indicates the path of the target file <br/> var <br/> dt1, dt2: integer; <br/> FS: tfilestream; <br/> FCT, Flt: tfiletime; <br/> begin <br/> dt1: = datetimetofiledate (trunc (form1.datetimepicker1. date) + frac (form1.datetimepicker2. time); <br/> dt2: = datetimetofiledate (trunc (form1.datetimepicker3. date) + frac (form1.datetimepicker4. time); <br/> // The information of the user input in datatimepicker, form1.datetimepicker1. date and form1.datetimepicker2. time is the creation time, form1.datetimepicker3. date and form1.datetimepicker4. time is the modification time <br/> try <br/> FS: = tfilestream. create (TF, fmopenreadwrite); // create a tfilestream <br/> try <br/> If dosdatetimetofiletime (longrec (dt1 ). hi, longrec (dt1 ). lo, FCT) and localfiletimetofiletime (FCT, FCT) and dosdatetimetofiletime (longrec (dt2 ). hi, longrec (dt2 ). lo, Flt) and localfiletimetofiletime (FLT, Flt) <br/> then setfiletime (FS. handle, @ FCT, @ FLT, @ Flt); // sets the file time attribute <br/> finally <br/> FS. free; // release <br/> end; <br/> messagedlg ('Modified successfully', mtconfirmation, [mbok], 0 ); // prompt <br/> success T <br/> messagedlg ('modification failed', mterror, [mbok], 0 ); // failure due to the usage of the target file <br/> end; <br/> procedure tform1.button1click (Sender: tobject ); <br/> begin <br/> setfiledatetime (edit1.text); // press start to set the file time <br/> end; <br/> procedure tform1.button2click (Sender: tobject); <br/> begin <br/> If opendialog1.execute then edit1.text: = opendialog1.filename; // select a file <br/> end; <br/> end.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.