如何将文件拷到另一个目录中?
我要将一个图片拷贝到相对路径中的一个文件夹中(map 文件夹,他在资程序目录中,但如果整个程序拷贝到其它地方,所以要使用相对目录)。
copyfileto(openpicturedialog1.filename,'..\map\'+name+'.bmp');//name存放图片拷贝到另一个地方的名称。当是不知错在那里。

解决方案 »

  1.   

    有CopyFileTo这个函数马?我没找到。
    CopyFile(LPCTSTR lpszExistingFile, LPCTSTR lpszNewFile, BOOL fFailIfExists);
    那你那个例子中的数据来说应该是这样
    CopyFile(pchar(openpicturedialog1.filename),pchar(GetCurrentDir+name+'.bmp'),false);
      

  2.   

    CopyFile(pchar(openpicturedialog1.filename),pchar(GetCurrentDir+name+'.bmp'),false);
    最后那个false是什么意思。
    谢谢!
      

  3.   

    false会覆盖已经存在的目标文件,true表示不覆盖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.
      

  4.   

    GetCurrentDir是得到现在源程序所在的文件夹吗,
    那在这个文件夹下的map应是:
    CopyFile(pchar(openpicturedialog1.filename),pchar(GetCurrentDir+‘\map\’+name+'.bmp'),false);是吗?
      

  5.   

    是啊是啊。不过如果当前目录是在根目录下,比如说在D:根目录下,GetCurrentDir 得到的值是这样'D:\',在这种情况下就不能使'\map'因为会有两个'\',所以你要判断一下GetCurrentDir得到的字符串最后一位是不是'\'再决定加不加'\',呵呵。记得好像是这样,不过懒得去测试,你自己可以试试看是不是这样。
      

  6.   

    GetCurrentDir得到的路径是用户当前操作路径。在我的程序中:
    CopyFile(pchar(openpicturedialog1.filename),pchar(GetCurrentDir+‘\map\’+name+'.bmp'),false)//把用户打开的图片,要保存到源程序的map目录下。
    用GetCurrentDir不对啊!!!??
    当程序打包后,用户安装后,会在他的安装目录下产生map文件夹。然后在把用户打开的图片拷到map文件夹下。
      

  7.   

    ExtractFilePath(Application.ExeName)可以得到当前应用程序Exe的路径,然后你再根据这个路径写就好了