文件复制粘贴

VC里移动和复制文件,删除文件的方法 文件属性设置的方法  
CopyFile和MoveFile,SetFileAttributes,rename 
BOOL CopyFile( 
  LPCTSTR lpExistingFileName, // name of an existing file   LPCTSTR lpNewFileName,      // name of new file 
  BOOL bFailIfExists          // operation if file exists );  
注意: 
1、文件的路径名中必须是为\\,而不是\,\是无效的,我已经试过了 
2、bFailIfExists  的值为TRUE时,如果要复制的文件在目标文件夹下已经存在,则复制失败。值为FALSE,则允许覆盖。  
BOOL MoveFile( 
  LPCTSTR lpExistingFileName, // file name   LPCTSTR lpNewFileName       // new file name ); 注意: 
其复制的文件名和CopyFile也是一样的。 
 
DeleteFile 
The DeleteFile function deletes an existing file.  BOOL DeleteFile( 
  LPCTSTR lpFileName   // file name ); 
 
  
BOOL SetFileAttributes( 
  LPCTSTR lpFileName,      // file name   DWORD dwFileAttributes   // attributes ); 注意: 
dwFileAttributes为属性设置,有如下 












 
 
int rename( const char *oldname, const char *newname ); oldname和newname 也是一样是文件名(包含路径), 
 
上面三个函数的返回值如果为0,则说明操作失败,为非零值说明操作成功。  
以上两个函数包含在windows.h头文件中。  例子  
#include <windows.h> #include <iostream> using namespace std;  
void main() { 
  CopyFile("D:\\DSC00008.JPG","E:\\mv\\1.jpg",false); 
  MoveFile("D:\\javahe和MySQL实例.doc","E:\\mv\\2.doc"); SetFileAttributes("E:\\mv\\2.doc",FILE_ATTRIBUTE_HIDDEN); rename("E:\\mv\\2.doc","E:\\mv\\javahe和MySQL实例.doc");   cout<<"复制成功";  } 
 
还有CreateFile,在MSDN里可以查到。要用到的时候再去查询吧
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值