找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 357|回复: 1

c++中可以重新命名文件吗

[复制链接]
发表于 2009-11-3 03:27:06 | 显示全部楼层 |阅读模式 IP:江苏扬州
文章结束


2007-12-1 11:56:02 HJin

等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
第 2 楼   得分:0  
rename function
int rename ( const char * oldname, const char * newname ); <cstdio>

Rename file

Changes the name of the file or directory specified by oldname to newname.
If oldname and newname specify different paths and this is supported by the system, the file is moved to the new location.
This is an operation performed directly on a file; No streams are involved in the operation.


Parameters
oldname
C string containing the name of the file to be renamed and/or moved. This file must exist and the correct writing permissions should be available.
newname
C string containing the new name for the file. This shall not be the name of an existing file; if it is, the behavior to be expected depends on the running environment, which may either be failure or overriding.

Return value
If the file is successfully renamed, a zero value is returned.
On failure, a nonzero value is reurned and the errno variable is set to the corresponding error code. Error codes are numerical values representing the type of failure occurred. A string interpreting this value can be printed to the standard error stream by a call to perror.

Example
/* rename example */
#include <stdio.h>

int main ()
{
  int result;
  char oldname[] ="oldname.txt";
  char newname[] ="newname.txt";
  result= rename( oldname , newname );
  if ( result == 0 )
    puts ( "File successfully renamed" );
  else
    perror( "Error renaming file" );
  return 0;
}


If the file oldname.txt could be succesfully renamed to newname.txt the following message would be written to stdout:
File successfully renamed

Otherwise, a message similar to this will be written to stderr:
Error renaming file: Permission denied


See also
remove Remove file (function)

文章结束


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.  2007-12-1 14:04:11 21/1页1关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.054699 second(s), 9 queries. LinezingStat
Copyright?2004-2008, BCCN.NET, All Rights Reserved
发表于 2009-11-3 03:27:07 | 显示全部楼层 IP:江苏扬州
rename function
int rename ( const char * oldname, const char * newname ); <cstdio>

Rename file

Changes the name of the file or directory specified by oldname to newname.
If oldname and newname specify different paths and this is supported by the system, the file is moved to the new location.
This is an operation performed directly on a file; No streams are involved in the operation.


Parameters
oldname
C string containing the name of the file to be renamed and/or moved. This file must exist and the correct writing permissions should be available.
newname
C string containing the new name for the file. This shall not be the name of an existing file; if it is, the behavior to be expected depends on the running environment, which may either be failure or overriding.

Return value
If the file is successfully renamed, a zero value is returned.
On failure, a nonzero value is reurned and the errno variable is set to the corresponding error code. Error codes are numerical values representing the type of failure occurred. A string interpreting this value can be printed to the standard error stream by a call to perror.

Example
/* rename example */
#include <stdio.h>

int main ()
{
  int result;
  char oldname[] ="oldname.txt";
  char newname[] ="newname.txt";
  result= rename( oldname , newname );
  if ( result == 0 )
    puts ( "File successfully renamed" );
  else
    perror( "Error renaming file" );
  return 0;
}


If the file oldname.txt could be succesfully renamed to newname.txt the following message would be written to stdout:
File successfully renamed

Otherwise, a message similar to this will be written to stderr:
Error renaming file: Permission denied


See also
remove Remove file (function)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 13:25 , Processed in 0.255183 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表