如何在文档文件夹中创建目录
How do I create a directory inside of the documents folder?
这是我试图找到任何用户中的文档文件夹,然后创建一个文件夹。我对c++还比较陌生,只是想弄清楚目录是如何工作的
void useraccess::createtxt() {
//name is a pre-defined string
cout << "Creating usern";
#ifdef _WIN32
LPTSTR path = NULL;
HRESULT hr = SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &path);
if (SUCCEEDED(hr)) {
path + \name;
CreateDirectoryA(path, NULL);
}
else {
cout << "Error finding documents folder";
}
#elif __APPLE__
#else
cout << "Error";
#endif
}
#include <cstdlib>
#include <string>
#include <iostream>
#include <windows.h>
#include <shlobj_core.h>
int main()
{
PWSTR path_temp;
if (SHGetKnownFolderPath(FOLDERID_PublicDocuments, 0, nullptr, &path_temp) != S_OK) {
std::cerr << "SHGetKnownFolderPath() failed :(nn";
return EXIT_FAILURE;
}
std::wstring path{ path_temp };
CoTaskMemFree(path_temp);
path += L"\foobar";
if (SHCreateDirectory(nullptr, path.c_str()) != ERROR_SUCCESS) {
std::cerr << "SHCreateDirectory() failed :(nn";
return EXIT_FAILURE;
}
std::wcout << L"Directory "" << path << L"" created.nn";
}
相关文章:
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 如何在文档文件夹中创建目录
- 介子复制/安装头文件到输出目录并保持文件夹结构
- 如何从Windows控制台调用.exe(C++)以在不同的目录(或任何目录)中创建文件夹?
- 如何使用Windows API C++更改已创建的文件夹/目录安全权限
- 如何在 C++ 中创建一个适用于 Windwos 和 Linux 的文件夹(目录)
- 我如何用Quazip将目录/文件夹汇总
- 嵌入 LuaJIT - 创建包含文件夹
- 有没有办法使用 WINAPI 或 Embarcadero C++ Builder XE 创建共享目录/文件夹
- 在 Visual Studio 项目中创建包含文件夹和 Lib 文件夹
- 以编程方式在非 Windows 计算机中创建共享文件夹
- 如何在C++中创建一个没有路径名的文件夹,只有要创建的文件夹的名称
- 使用 c++ 创建/删除文件夹
- 仅通过本机代码检查apk中是否存在目录(文件夹)
- Win32“浏览文件夹”对话框:用户创建新文件夹时返回错误的文件夹
- 在SDL中创建一个新文件夹或目录
- 在c++中在当前目录中创建多个文件夹
- 在iOS中使用c++创建目录/文件
- 创建特殊文件夹(如控制面板或计算机管理)的快捷方式
- 在使用mkdir()创建一个文件夹后,我如何让程序将文件和其他信息保存到新文件夹中?