檔案處理

使用這些常式以建立、刪除和管理檔案並設定、檢查檔案存取權限。

C 執行階段程式庫同始開啟檔案數目的上限為 512。 嘗試開啟大於數目上限的檔案描述項或檔案資料流將導致程式發生錯誤。 使用 _setmaxstdio 變更此編號。

下列常式處理檔案描述項所指定的檔案。

檔案處理常式 (檔案描述)

常式

使用

.NET Framework 對等用法

_chsize,_chsize_s

變更檔案大小

System::IO::Stream::SetLengthSystem::IO::FileStream::SetLength

_filelength、_filelengthi64

取得檔案長度。

System::IO::Stream::LengthSystem::IO::FileStream::Length

_fstat、_fstat32、_fstat64、_fstati64、_fstat32i64、_fstat64i32

取得有關描述項的檔案狀態資訊。

不適用。 若要呼叫標準 C 函式,請使用 PInvoke。 如需詳細資訊,請參閱平台叫用範例

_get_osfhandle

傳回與現有 C 執行階段描述項的作業系統檔案處理常式。

不適用。 若要呼叫標準 C 函式,請使用 PInvoke。 如需詳細資訊,請參閱平台叫用範例

_isatty

檢查字元裝置

System::IO::Stream::CanWriteSystem::IO::FileStream::CanWrite

_locking

檔案鎖定區域

System::IO::FileStream::Lock

_open_osfhandle

將現有作業系統檔案處理常式與 C 執行階段檔案作關聯。

System::IO::FileStream::Handle

_setmode

設定檔案轉譯模式

System::IO::BinaryReader 類別System::IO::TextReader 類別

下列常式處理有路徑或檔名指定的檔案

檔案處理常式 (路徑或檔名)

常式

使用

.NET Framework 對等用法

_access、_waccess, _access_s、_waccess_s

檢查檔案的使用權限設定。

System::IO::FileAccess 列舉

_chmod、_wchmod

變更檔案的使用權限設定。

System::IO::File::SetAttributesSystem::Security::Permissions::FileIOPermission

_fullpath、_wfullpath

將相對路徑展開為絕對路徑名稱

System::IO::File::Create

_makepath、_wmakepath, _makepath_s、_wmakepath_s

將路徑元件合併成單一、完整路徑。

System::IO::File::Create

_mktemp, _wmktemp, _mktemp_s、_wmktemp_s

建立唯一檔名。

不適用。 若要呼叫標準 C 函式,請使用 PInvoke。 如需詳細資訊,請參閱平台叫用範例

remove、_wremove

刪除檔案

System::IO::File::Delete

rename、_wrename

重新命名檔案

System::IO::File::Move

_splitpath, _wsplitpath, _splitpath_s、_wsplitpath_s

將路徑解析成元件

不適用。 若要呼叫標準 C 函式,請使用 PInvoke。 如需詳細資訊,請參閱平台叫用範例

_stat, _stat64, _stati64, _wstat, _wstat64, _wstati64

取得有關具名檔案的狀態資訊。

System::IO::File::GetAttributesSystem::IO::File::GetCreationTimeSystem::IO::File::GetLastAccessTimeSystem::IO::File::GetLastWriteTime

_umask, _umask_s

將程式建立的新檔案設定為預設權限遮罩

System::IO::File::SetAttributes

_unlink、_wunlink

刪除檔案

System::IO::File::Delete

下列常式用於開啟檔案。

檔案處理常式 (開啟檔案)

常式

使用

.NET Framework 對等用法

fopen、_wfopen, fopen_s、_wfopen_s

開啟檔案並回傳指向此檔案的指標。

System::IO::File::OpenSystem::IO::FileStream::FileStream

_fsopen、_wfsopen

開啟檔案共用的資料流並回傳指向此檔案的指標。

System::IO::File::OpenSystem::IO::FileStream::FileStream

_open、_wopen

開啟檔案並將回傳此檔案的檔案描述項。

System::IO::File::OpenSystem::IO::FileStream::FileStream

_sopen、_wsopen, _sopen_s、_wsopen_s

開啟檔案共用的檔案並回傳此檔案的檔案描述項。

 

_pipe

建立用於讀取和寫入的管道。

不適用。 若要呼叫標準 C 函式,請使用 PInvoke。 如需詳細資訊,請參閱平台叫用範例

freopen、_wfreopen, freopen_s、_wfreopen_s

重新指派檔案指標。

System::IO::File::OpenSystem::IO::FileStream::FileStream

下列函式提供在 FILE 結構、檔案描述項和 Win32 檔案處理之間變更檔案表示的方法。

_fdopen、_wfdopen

將資料流與先前用於低階 I/O 開啟的檔案作關聯,並回傳指向此資料流的指標。

System::IO::FileStream::FileStream

_fileno

取得與資料流作關聯的檔案描述項。

System::IO::FileStream::Handle

_get_osfhandle

傳回與現有 C 執行階段描述項的作業系統檔案處理常式。

不適用。 若要呼叫標準 C 函式,請使用 PInvoke。 如需詳細資訊,請參閱平台叫用範例

_open_osfhandle

將現有作業系統檔案處理常式與 C 執行階段檔案作關聯。

System::IO::FileStream::Handle

下列的 Win32 函式也用於開啟檔案和管道:

請參閱

參考

依分類區分的執行階段常式

目錄控制

系統呼叫