文件处理函数大全

Use these routines to create, delete, and manipulate files and to set and check file-access permissions.

The C run-time libraries have a 512 limit for the number of files that can be open at any one time. Attempting to open more than the maximum number of file descriptors or file streams causes program failure. Use _setmaxstdio to change this number.

The following routines operate on files designated by a file descriptor.

Routine

Use

.NET Framework equivalent

_chsize,_chsize_s

Change file size

System::IO::Stream::SetLength, System::IO::FileStream::SetLength

_filelength, _filelengthi64

Get file length

System::IO::Stream::SetLength, System::IO::FileStream::SetLength

_fstat, _fstat32, _fstat64, _fstati64, _fstat32i64, _fstat64i32

Get file-status information on descriptor

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_get_osfhandle

Return operating-system file handle associated with existing C run-time file descriptor

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_isatty

Check for character device

System::IO::Stream::CanWrite, System::IO::FileStream::CanWrite

_locking

Lock areas of file

System::IO::FileStream::Lock

_open_osfhandle

Associate C run-time file descriptor with existing operating-system file handle

System::IO::FileStream::Handle

_setmode

Set file-translation mode

System::IO::BinaryReader Class, System::IO::TextReader Class

The following routines operate on files specified by a path or filename.

Routine

Use

.NET Framework equivalent

_access, _waccess, _access_s, _waccess_s

Check file-permission setting

System::IO::FileAccess Enumeration

_chmod, _wchmod

Change file-permission setting

System::IO::File::SetAttributes, System::Security::Permissions::FileIOPermission

_fullpath, _wfullpath

Expand a relative path to its absolute path name

System::IO::File::Create

_makepath, _wmakepath, _makepath_s, _wmakepath_s

Merge path components into single, full path

System::IO::File::Create

_mktemp, _wmktemp, _mktemp_s, _wmktemp_s

Create unique filename

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

remove, _wremove

Delete file

System::IO::File::Delete

rename, _wrename

Rename file

System::IO::File::Move

_splitpath, _wsplitpath, _splitpath_s, _wsplitpath_s

Parse path into components

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_stat, _stat64, _stati64, _wstat, _wstat64, _wstati64

Get file-status information on named file

System::IO::File::GetAttributes, System::IO::File::GetCreationTime, System::IO::File::GetLastAccessTime, System::IO::File::GetLastWriteTime

_umask, _umask_s

Set default permission mask for new files created by program

System::IO::File::SetAttributes

_unlink, _wunlink

Delete file

System::IO::File::Delete

The following routines open files.

Routine

Use

.NET Framework equivalent

fopen, _wfopen, fopen_s, _wfopen_s

Opens a file and returns a pointer to the open file.

System::IO::File::Open, System::IO::FileStream::FileStream

_fsopen, _wfsopen

Open a stream with file sharing and returns a pointer to the open file.

System::IO::File::Open, System::IO::FileStream::FileStream

_open, _wopen

Opens a file and returns a file descriptor to the opened file.

System::IO::File::Open, System::IO::FileStream::FileStream

_sopen, _wsopen, _sopen_s, _wsopen_s

Open a file with file sharing and returns a file descriptor to the open file.

 

_pipe

Creates a pipe for reading and writing.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

freopen, _wfreopen, freopen_s, _wfreopen_s

Reassign a file pointer.

System::IO::File::Open, System::IO::FileStream::FileStream

The following functions provide a way to change the representation of the file between aFILE structure, a file descriptor, and a Win32 file handle.

_fdopen, _wfdopen

Associates a stream with a file that was previously opened for low-level I/O and returns a pointer to the open stream.

System::IO::FileStream::FileStream

_fileno

Gets the file descriptor associated with a stream.

System::IO::FileStream::Handle

_get_osfhandle

Return operating-system file handle associated with existing C run-time file descriptor

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_open_osfhandle

Associates C run-time file descriptor with an existing operating-system file handle.

System::IO::FileStream::Handle

The following Win32 functions also open files and pipes:

  • CreateFile

  • CreatePipe

  • CreateNamedPipe


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值