CopyFile/fi: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: CopyFile/fi
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Tiedoston kopiointi | |
| 2 | + | ||
| 3 | + | Lazaruksen [[Unit/fi|Käännösyksikkö]] [[fileutil/fi|fileutil]] (jossa on [[UTF-8/fi|UTF-8]] korvaukset FPC [[RTL/fi|RTL]] koodille ja lisänä tiedoston/hakemiston käsittelyrutiineja) | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | // flags for copy | |
| 7 | + | type | |
| 8 | + | TCopyFileFlag = ( | |
| 9 | + | cffOverwriteFile, | |
| 10 | + | cffCreateDestDirectory, | |
| 11 | + | cffPreserveTime | |
| 12 | + | ); | |
| 13 | + | TCopyFileFlags = set of TCopyFileFlag; | |
| 14 | + | ||
| 15 | + | function CopyFile(const SrcFilename, DestFilename: string): boolean; | |
| 16 | + | function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean): boolean; | |
| 17 | + | function CopyFile(const SrcFilename, DestFilename: string; Flags: TCopyFileFlags=[cffOverwriteFile]): boolean; | |
| 18 | + | ``` | |
| 19 | + | ||
| 20 | + | [[Function/fi|Funktio]] **copyfile** kopio tiedoston kohdetiedoston sijaintiin. Valinnaisesti se säilyttää tiedoston aikaleiman. | |
| 21 | + | ||
| 22 | + | Funktio palauttaa [[Boolean/fi|boolean]] arvon [[True/fi|true]], jos se onnistui ja [[False/fi|falsen]] jos tapahtui virhe. | |
| 23 | + | ||
| 24 | + | > **Note:** Jos halutaan käyttää tätä funktiota [[Command-line interface/fi|komentoriviohjelmissa]] niin pitää lisätä projektin vaatimuksiin [[LazUtils/fi|LazUtils]], jolloin ei tuoda mukaan koko [[LCL/fi|LCL]]-kirjastoa | |
| 25 | + | ||
| 26 | + | ## Windows esimerkki | |
| 27 | + | ||
| 28 | + | ``` pascal | |
| 29 | + | uses | |
| 30 | + | ... | |
| 31 | + | fileutil | |
| 32 | + | ... | |
| 33 | + | CopyFile('c:\autoexec.bat','c:\windows\temp\autoexec.bat.backup'); | |
| 34 | + | ``` | |
| 35 | + | ||
| 36 | + | ## Lazarus esimerkki | |
| 37 | + | ||
| 38 | + | Seuraavia komponentteja tai funktioita käytetään tässä esimerkissä: | |
| 39 | + | ||
| 40 | + | - [[TOpenDialog/fi|TOpenDialog]]  | |
| 41 | + | - [[TSaveDialog/fi|TSaveDialog]]  | |
| 42 | + | - [[Dialog Examples/fi|MessageDlg]] | |
| 43 | + | ||
| 44 | + | ``` pascal | |
| 45 | + | ||
| 46 | + | procedure TForm1.Button1Click(Sender: TObject); | |
| 47 | + | var | |
| 48 | + | ok:boolean; | |
| 49 | + | begin | |
| 50 | + | ok := false; | |
| 51 | + | if OpenDialog1.Execute then | |
| 52 | + | if SaveDialog1.Execute then | |
| 53 | + | ok := CopyFile(OpenDialog1.FileName, SaveDialog1.FileName); | |
| 54 | + | if ok then MessageDlg('File '+OpenDialog1.FileName+' successfully copied to '+ | |
| 55 | + | SaveDialog1.FileName,mtInformation,[mbOk],0) | |
| 56 | + | else MessageDlg('Copying failed',mtWarning,[mbOk],0); | |
| 57 | + | end; | |
| 58 | + | ``` | |
| 59 | + | ||
| 60 | + | --- | |
| 61 | + | *From the Free Pascal wiki, page "CopyFile/fi", as it stood on 2019-09-08 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
