Delphi File Operations

Source: Internet
Author: User

Copyfile(Pchar('newfile.txt '), pchar (' // computername/direction/targer.txt '), false );

◇ [Delphi] Obtain the Windows directory
Uses shellapi;
VaR WINDIR: array [0 .. 255] of char;
Getwindowsdirectory (WINDIR, sizeof (WINDIR ));
Or read from the Registry, Location:
HKEY_LOCAL_MACHINE/software/Microsoft/Windows/CurrentVersion
Systemroot key, for example, C:/Windows

◇ [Delphi] File and directory operations
Chdir ('C:/abcdir'); go to the directory
Mkdir ('dirname'); create a directory
Rmdir ('dirname'); Delete the Directory
Getcurrentdir; // get the name of the current directory, no '/'
Getdir (0, S); // get the working directory name s: = 'C:/abcdir ';
Deletfile('abc.txt '); // delete an object
Renamefile('old.txt', 'new.txt '); // rename the file
Extractfilename (filelistbox1.filename); // obtain the file name
Extractfileext (filelistbox1.filename); // obtain File suffix

◇ [Delphi] Processing file attributes
ATTR: = filegetattr (filelistbox1.filename );
If (ATTR and fareadonly) = fareadonly then... // read-only
If (ATTR and fasysfile) = fasysfile then... // System
If (ATTR and faarchive) = faarchive then... // Archive
If (ATTR and fahidden) = fahidden then... // hide

◇ [Delphi] Execute files outside the program
Winexec // call the executable file
Winexec ('COMMAND. com/C copy *. * C:/', sw_normal );
Winexec ('start abc.txt ');
ShellExecute or shellexecuteex // start the File Association Program
Function executefile (const filename, Params, defaultdir: string; showcmd: integer): thandle;
Executefile ('C:/ABC/a.txt ', 'x. abc', 'c:/ABC/', 0 );
Executefile ('HTTP: // tingweb.yeah.net ', '','', 0 );
Executefile ('mailto: tingweb@wx88.net ', '','', 0 );

◇ Source Directory : // HP/authorized use/foreign trade business system /.
Target Directory: C:/zkf

1

FindDelphiBuilt-inCopyfileFunction, but does not support multiple files, which is too troublesome

2

Stupid method:

1. Create a local Batch File
Copy conCopyfile. Bat
@ Echo off
Copy // HP/authorized use/foreign trade business system/*. * C:/zkf
Echo copied !!
^ Z // save
2. You only need to execute this batch file. Of course, it depends on your usage.
You can alsoDelphiOpen the above batch file to achieve the same purpose.

3

You can use this API function as long as you have the required permissions:
Procedure tform1.bitbtn1click (Sender: tobject );
VaR F: tshfileopstruct; // uses shellapi;
B: integer;
Begin
F. WND: = form1.handle;
F. wfunc: = fo_copy; // fo_delete, copy, move, rename
F. pfrom: = pchar ('// HP/authorized/ Foreign Trade Business System ');
F. PTO: = pchar ('C:/zkf ');
F. fflags: = fof_allowundo; // or fof_silent or fof_noconfirmation;
B: = shfileoperation (f );
If F. fanyoperationsaborted then showmessage ('user cancels operation ');
If B = 0 Then exit;
Beep; showmessage ('file operation not implemented! ');
End;
 

4

It does not appear during replication. File Already exists. Do you want to overwrite the question?

5

Haha, watchDelphiHelp!

Just put f. fflags: = fof_allowundo; // or fof_silent or fof_noconfirmation
Change to F. fflags: = fof_silent or fof_noconfirmation.

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: info-contact@alibabacloud.com 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.