File Handling
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.
File-Handling Routines (File Descriptor)
Routine |
Use |
.NET Framework equivalent |
---|---|---|
Change file size |
System::IO::Stream::SetLength, System::IO::FileStream::SetLength |
|
Get file length |
||
_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. |
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. |
|
Check for character device |
System::IO::Stream::CanWrite, System::IO::FileStream::CanWrite |
|
Lock areas of file |
||
Associate C run-time file descriptor with existing operating-system file handle |
||
Set file-translation mode |
System::IO::BinaryReader Class, System::IO::TextReader Class |
The following routines operate on files specified by a path or filename.
File-Handling Routines (Path or Filename)
Routine |
Use |
.NET Framework equivalent |
---|---|---|
Check file-permission setting |
||
Change file-permission setting |
System::IO::File::SetAttributes, System::Security::Permissions::FileIOPermission |
|
Expand a relative path to its absolute path name |
||
Merge path components into single, full path |
||
Create unique filename |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
|
Delete file |
||
Rename file |
||
Parse path into components |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
|
Get file-status information on named file |
System::IO::File::GetAttributes, System::IO::File::GetCreationTime, System::IO::File::GetLastAccessTime, System::IO::File::GetLastWriteTime |
|
Set default permission mask for new files created by program |
||
Delete file |
The following routines open files.
File-Handling Routines (Open File)
Routine |
Use |
.NET Framework equivalent |
---|---|---|
Opens a file and returns a pointer to the open file. |
System::IO::File::Open, System::IO::FileStream::FileStream |
|
Open a stream with file sharing and returns a pointer to the open file. |
System::IO::File::Open, System::IO::FileStream::FileStream |
|
Opens a file and returns a file descriptor to the opened file. |
System::IO::File::Open, System::IO::FileStream::FileStream |
|
Open a file with file sharing and returns a file descriptor to the open file. |
|
|
Creates a pipe for reading and writing. |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
|
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 a FILE structure, a file descriptor, and a Win32 file handle.
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 |
|
Gets the file descriptor associated with a stream. |
||
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. |
|
Associates C run-time file descriptor with an existing operating-system file handle. |
The following Win32 functions also open files and pipes: