delphi 文件操作

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

◇[DELPHI]取得WINDOWS目录
uses shellapi;
var windir:array[0..255] of char;
getwindowsdirectory(windir,sizeof(windir));
或者从注册表中读取,位置:
HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion
SystemRoot键,取得如:C:/WINDOWS

◇[DELPHI]关于文件、目录操作
Chdir('c:/abcdir');转到目录
Mkdir('dirname');建立目录
Rmdir('dirname');删除目录
GetCurrentDir;//取当前目录名,无'/'
Getdir(0,s);//取工作目录名s:='c:/abcdir';
Deletfile('abc.txt');//删除文件
Renamefile('old.txt','new.txt');//文件更名
ExtractFilename(filelistbox1.filename);//取文件名
ExtractFileExt(filelistbox1.filename);//取文件后缀

◇[DELPHI]处理文件属性
attr:=filegetattr(filelistbox1.filename);
if (attr and faReadonly)=faReadonly then ... //只读
if (attr and faSysfile)=faSysfile then ... //系统
if (attr and faArchive)=faArchive then ... //存档
if (attr and faHidden)=faHidden then ... //隐藏

◇[DELPHI]执行程序外文件
WINEXEC//调用可执行文件
winexec('command.com /c copy *.* c:/',SW_Normal);
winexec('start abc.txt');
ShellExecute或ShellExecuteEx//启动文件关联程序
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:[email protected]','','',0);

◇源目录://Hp/授权使用/外贸业务系统/.  
  目的目录:c:/zkf

1

找到一个DELPHI自带的COPYFILE函数,但不支持多文件,太麻烦

2

笨方法:  
   
  1、你在本地建一个批处理文件  
            Copy   Con   CopyFile.bat  
                    @echo   off  
                      Copy   //Hp/授权使用/外贸业务系统/*.*   c:/zkf  
                    echo   拷贝完毕!!  
                    ^z   //   save  
  2、你只要执行这个批处理文件就可以,当然,要看你使用的场合。  
  你也可以在Delphi中打开上述批处理文件,以达到相同的目的.

3

只要你有相应的权限,可以使用这个API函数:  
  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/授权使用/外贸业务系统');  
        f.pTo:=pChar('c:/zkf');  
        f.fFlags:=FOF_ALLOWUNDO   ;//or   FOF_SILENT   or   FOF_NOCONFIRMATION;  
        b:=ShFileOperation(f);  
        if   f.fAnyOperationsAborted   then   ShowMessage('用户取消操作');  
        if   b=0     then   exit;  
        beep;   ShowMessage('文件操作没有实现!');  
  end;

4

那在复制时不出现文件已存在,是否覆盖的提问该怎么做?

5

呵呵,看Delphi的帮助嘛!  
   
  只要把f.fFlags:=FOF_ALLOWUNDO   ;//or   FOF_SILENT   or   FOF_NOCONFIRMATION  
  改为f.fFlags:=FOF_SILENT   or   FOF_NOCONFIRMATION就可以了.    

你可能感兴趣的:(c,windows,function,Integer,delete,Delphi)