copyfile
fold,fnew:pchar;
strpcopy(fold,'c:\11212.txt');
strpcopy(fnew,'c:\1.txt');copyfile(fold,fnew,true);he CopyFile function copies an existing file to a new file. BOOL CopyFile(    LPCTSTR lpExistingFileName, // pointer to name of an existing file 
    LPCTSTR lpNewFileName, // pointer to filename to copy to 
    BOOL bFailIfExists  // flag for operation if file exists 
   );
 ParameterslpExistingFileNamePoints to a null-terminated string that specifies the name of an existing file. lpNewFileNamePoints to a null-terminated string that specifies the name of the new file. bFailIfExistsSpecifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.  Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. ResSecurity attributes for the existing file are not copied to the new file. 
File attributes (FILE_ATTRIBUTE_*) for the existing file are copied to the new file. For example, if an existing file has the FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute. For further information on file attributes, see CreateFile.See AlsoCreateFile, MoveFile 

解决方案 »

  1.   

    如果你有DELPHI5开发人员指南,那有个例子.如果你没有,你可以到http://abcdelphi.myetang.com/的控件一栏中去下载一个控件.基本的原理目是使用SHFileOperation()来操作.
      

  2.   

    Simple Example of Managing Files with SHFileOperation
    The following sample console application illustrates the use of SHFileOperation to copy files from one directory to another. The source and destination directories, C:\My_Docs and C:\My_Docs2, are hard-coded into the application for simplicity.#include <shlobj.h>
    #include <shlwapi.h>main()
    {
        IShellFolder *psfDeskTop = NULL;
        IShellFolder *psfDocFiles = NULL;
        IMalloc *pMalloc = NULL;
        LPITEMIDLIST pidlDocFiles = NULL;
        LPITEMIDLIST pidlItems = NULL;
        IEnumIDList *ppenum = NULL;
        SHFILEOPSTRUCT sfo;
        STRRET strDispName;
        TCHAR szParseName[MAX_PATH];
        TCHAR szSourceFiles[256];
        int i;
        int iBufPos = 0;
        ULONG chEaten;
        ULONG celtFetched;
        HRESULT hr;    pzSourceFiles[0] = '\0';
        hr = SHGetMalloc(&pMalloc);
        hr = SHGetDesktopFolder(&psfDeskTop);    hr = psfDeskTop->ParseDisplayName(NULL, NULL, L"c:\\My_Docs", 
             &chEaten, &pidlDocFiles, NULL);
        hr = psfDeskTop->BindToObject(pidlDocFiles, NULL, IID_IShellFolder, 
             (LPVOID *) &psfDocFiles);
        hr = psfDeskTop->Release();    hr = psfDocFiles->EnumObjects(NULL,SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, 
             &ppenum);    while( (hr = ppenum->Next(1,&pidlItems, &celtFetched)) == S_OK 
           && (celtFetched) == 1)
        {
            psfDocFiles->GetDisplayNameOf(pidlItems, SHGDN_FORPARSING, 
                &strDispName);
            StrRetToBuf(&strDispName, pidlItems, szParseName, MAX_PATH);
            for(i=0;i<=lstrlen(szParseName); i++)
            {
                szSourceFiles[iBufPos++] = szParseName[i];
            }
            pMalloc->Free(pidlItems);
        }
    ppenum->Release();

        szSourceFiles[iBufPos] = '\0';    sfo.hwnd = NULL;
        sfo.wFunc = FO_COPY;
        sfo.pFrom = szSourceFiles;
        sfo.pTo = "c:\\My_Docs2\0";
        sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;    hr = SHFileOperation(&sfo);

        SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH, (LPCVOID) "c:\My_Docs2", 0);    pMalloc->Free(pidlDocFiles);
        psfDocFiles->Release();    return 0;
    }