c语言remove和rename不起作用,为何remove和rename没起作用?求指教(2)

当前位置:我的异常网» C语言 » 为何remove和rename没起作用?求指教

为何remove和rename没起作用?求指教(2)

www.myexceptions.net  网友分享于:2014-03-13  浏览:29次

_tremove remove remove _wremove

Example

/* REMOVE.C: This program uses remove to delete REMOVE.OBJ. */

#include 

void main( void )

{

if( remove( "remove.obj" ) == -1 )

perror( "Could not delete 'REMOVE.OBJ'" );

else

printf( "Deleted 'REMOVE.OBJ'\n" );

}

Output

Deleted 'REMOVE.OBJ'

File Handling Routines

See Also   _unlink

rename, _wrename

Rename a file or directory.

int rename( const char *oldname, const char *newname );

int _wrename( const wchar_t *oldname, const wchar_t *newname );

Routine Required Header Compatibility

rename  or  ANSI, Win 95, Win NT

_wrename  or  Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version

LIBCMT.LIB Multithread static library, retail version

MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns 0 if it is successful. On an error, the function  returns a nonzero value and sets errno to one of the following values:

EACCES

File or directory specified by newname already exists or could not be created (invalid path); or oldname is a directory and newname specifies a different path.

ENOENT

File or path specified by oldname not found.

EINVAL

Name contains invalid characters.

For other possible return values, see _doserrno, _errno, syserrlist, and _sys_nerr.

Parameters

oldname

Pointer to old name

newname

Pointer to new name

Remarks

The rename function renames the file or directory specified by oldname to the name given by newname. The old name must be the path of an existing file or directory. The new name must not be the name of an existing file or directory. You can use rename to move a file from one directory or device to another by giving a different path in the newname argument. However, you cannot use rename to move a directory. Directories can be renamed, but not moved.

_wrename is a wide-character version of _rename; the arguments to _wrename are wide-character strings. _wrename and _rename behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined

_trename rename rename _wrename

Example

/* RENAMER.C: This program attempts to rename a file

* named RENAMER.OBJ to RENAMER.JBO. For this operation

* to succeed, a file named RENAMER.OBJ must exist and

* a file named RENAMER.JBO must not exist.

*/

#include 

void main( void )

{

int  result;

char old[] = "RENAMER.OBJ", new[] = "RENAMER.JBO";

/* Attempt to rename file: */

result = rename( old, new );

if( result != 0 )

printf( "Could not rename '%s'\n", old );

else

printf( "File '%s' renamed to '%s'\n", old, new );

}

Output

File 'RENAMER.OBJ' renamed to 'RENAMER.JBO'

File Handling Routines

亲,别每次都贴MSDN的说明,大家都可以自己去看的,你这样一贴上来,意义真不大

文章评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值