Getting a directory name from a filename(从文件名中获取目录名)
问题描述
我有一个文件名 (C:folderfoo.txt),我需要在非托管 C++ 中检索文件夹名称 (C:folder).在 C# 中,我会做这样的事情:
I have a filename (C:folderfoo.txt) and I need to retrieve the folder name (C:folder) in unmanaged C++. In C# I would do something like this:
string folder = new FileInfo("C:folderfoo.txt").DirectoryName;
是否有可以在非托管 C++ 中使用的函数从文件名中提取路径?
Is there a function that can be used in unmanaged C++ to extract the path from the filename?
推荐答案
为此有一个标准的 Windows 功能,PathRemoveFileSpec.如果您只支持 Windows 8 及更高版本,强烈建议使用 PathCchRemoveFileSpec 代替.在其他改进中,它不再限于 MAX_PATH (260) 个字符.
There is a standard Windows function for this, PathRemoveFileSpec. If you only support Windows 8 and later, it is highly recommended to use PathCchRemoveFileSpec instead. Among other improvements, it is no longer limited to MAX_PATH (260) characters.
这篇关于从文件名中获取目录名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从文件名中获取目录名
基础教程推荐
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- c++ STL设置差异 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
