如何通过 int-descriptor 找出文件名?(或"can I..?")

How to find out file name through int-descriptor? (or "can I..?")

本文关键字:何通过 can 文件名 int-descriptor      更新时间:2023-10-16

我以这种方式打开文件:

errno_t err01;   
int fHandle;
err01 = _sopen_s(&fHandle, fileName, _O_RDWR, _SH_DENYRW, 0);

现在,我应该将int-descriptor(在此示例中命名为 fHandle)作为文件的识别器。

问题:我只知道这个int-descriptor,获取与之相对应的文件名吗?(假设,打开文件后,我失去了fileName变量的值)

您应该能够像这样获取文件句柄:

HANDLE hFile;
int fHandle;
err01 = _sopen_s(&fHandle, "blah.txt", _O_RDWR, _SH_DENYRW, 0);
hFile = (HANDLE) _get_osfhandle(fHandle);

然后只使用与文件句柄一起使用的函数,例如

GetFinalPathNameByHandle(hFile, Path, BUFSIZE, VOLUME_NAME_NT);
_tprintf(TEXT("path is %sn"), Path);

hth