如何通过 int-descriptor 找出文件名?(或"can I..?")
How to find out file name through int-descriptor? (or "can I..?")
我以这种方式打开文件:
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
相关文章:
- 通过方法访问结构
- 通过递归进行因子分解
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 尝试通过多个向量访问变量时,向量下标超出范围
- C++如何通过用户输入删除列表元素
- 通过多个头文件使用常量变量
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 如何通过派生类函数更改基类中的向量
- 无法通过空白将文本文件行分隔为矢量
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- Ctypes wstring通过引用传递
- 变量没有改变?通过向量的函数调用
- 如何通过cpp程序运行shell脚本
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 在C++通过CAN发送部分数据
- 如何通过 int-descriptor 找出文件名?(或"can I..?")
- C++03 12.4/12对通过指针显式调用基类析构函数有何说明
- *val 和 &val 在 C++ 中通过引用传递时有何不同
- visual Can用VC10(sp1)编译的C++库可以通过用VC11编译的代码链接