- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下路径和文件名
"C:\\Users\\msi\\Desktop\\read-file\\read-file.sdf"
使用 PathFindExtensionW
函数,预期的返回字符串是 ".sdf"
但它返回 "."
而不是!
这是我的代码
:
#include <stdio.h>
#include <shlwapi.h>
#define FILENAME "C:\\Users\\msi\\Desktop\\read-file\\read-file.sdf" // current file-path
#define MAX_FILE_EXT 90 // maximum file-extension length
#define ERR_MSG "Cannot open the specific file!\n" // error message if couldn't open the file
#pragma comment(lib, "shlwapi.lib") // add this static library for using of PathFindExtension
int main(int argc, char *argv[])
{
WIN32_FIND_DATAW data = {0};
HANDLE fh = 0;
if((FindFirstFile(TEXT(FILENAME), &data)) != INVALID_HANDLE_VALUE)
{
WCHAR file_ext[MAX_FILE_EXT] = {0};
lstrcpy(file_ext, PathFindExtension(TEXT(FILENAME)));
printf("File-extension is : '%s'\n", PathFindExtensionW(TEXT(FILENAME)));
}
else
printf(ERR_MSG);
return 0;
}
顺便说一下,我使用了wchar_t*
,所以我不得不调用PathFindExtensionW
。虽然我调用了 PathFindExtension
,但它返回了相同的结果。
最佳答案
您的程序是 Unicode(推荐),您并不需要 TEXT
宏,它只在 UNICODE
时添加 L
前缀被定义为。你可以自己做:
const wchar_t *wstr = L"this is a wide char string"; //or const WCHAR*, same thing
PathFindExtension
是一个宏,定义UNICODE
时,定义为PathFindExtensionW
。
#ifdef UNICODE
#define PathFindExtension PathFindExtensionW
#else
#define PathFindExtension PathFindExtensionA
#endif // !UNICODE
所以你可以只写PathFindExtension
lstrcpy
复制没问题,但它是 Windows 特定的功能。新程序可以使用宽字符版本的字符串函数,wcscpy
代替 strcpy
,wcslen
代替 strlen
,wcsxxx
而不是 strxxx
...
"C:\\Users\\msi\\Desktop"
不应进行硬编码。使用SHGetKnownFolderPath
查找桌面路径,示例:
#include <windows.h>
#include <stdio.h>
#include <shlwapi.h>
#include <Shlobj.h>
#include <KnownFolders.h>
#pragma comment(lib, "shlwapi.lib")
int main(void)
{
wchar_t desktop[MAX_PATH];
//get desktop path:
wchar_t *ptr;
SHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, &ptr);
wcscpy_s(desktop, _countof(desktop), ptr);
CoTaskMemFree(ptr);
//make filename from desktop path:
wchar_t filename[MAX_PATH];
swprintf(filename, _countof(filename), L"%s\\read-file\\read-file.sdf", desktop);
if (PathFileExists(filename))
wprintf(L"File-extension is : '%s'\n", PathFindExtension(filename));
return 0;
}
关于c - PathFindExtensionW 始终返回 "."而不是完整扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51445421/
我有一个 .crt 文件。打开那个文件,我看到它以开头 -----BEGIN CERTIFICATE----- 如何从这个文件生成这 2 个文件?: 以-----BEGIN CERTIFICATE R
我有一个文件被加载到 fd.ChosenName 并想知道是否有一个快速的解决方案,例如与 stringbuilder 相反的截断文件名(扩展名)以用于显示目的。因此,如果 fd.ChosenName
我的文件名如下:name1.csv,我想提取该字符串的两个子字符串。一种将 name1 存储在一个变量中,另一种将扩展名 csv 存储在另一个变量中,但不带点。 我一直在寻找是否有像 Java 的 i
我正在尝试找出一种方法来确定我在 struts2 应用程序中上传的文件的文件类型。我的应用程序可以读取 CSV 和 XML 文件并根据上传的文件类型执行操作。我将该文件作为“File”类的实例。该文件
如何使用 NLP/信息提取 (IE) 方法检测/找出首字母缩略词的含义(扩展名)? 我们希望检测自由文本中是否使用了单词或其首字母缩略词,并将其映射到相同的实体/标记。 大多数在线论文都是关于医学缩略
我正在编写一个 shell 脚本,该脚本需要改变其行为,并根据特定 X11 扩展的存在或不存在为被调用程序提供不同的选项。我有一个可行的解决方案,但我希望有一个更干净的解决方案。我愿意考虑一个简单的
我要查找文件名的扩展名,扩展名只能是3个字符。 有点像, filename = str(input("Please enter filename: ")) 然后我想执行一个任务来查找扩展名,如果扩展名
我正在开发一种文档管理系统。最终用户是企业级用户。 我目前仅检查并允许上传符合以下条件之一的文件: "png|jpe?g|gif|xls|doc|docx|csv|ppt|txt|pdf|rtf" 我
尝试将文件列表添加到 Jlist,然后过滤 JList 中的文件以仅返回 .txt 文件和固定字符长度。还尝试删除返回的文件路径,并仅在文件 JList 中显示文件名+扩展名。 到目前为止,除了删除文
File.py file = fields.Binary('File') @api.multi def get_file(self): if self.file: xsl_fi
我尝试使用导航 Controller 使我的应用程序处于纵向模式我收到此错误 iam usring Xcode7 and Swift 2 And Target System IOS 9.3 声明仅在文
这个问题在这里已经有了答案: Test whether a glob has any matches in Bash (22 个回答) 关闭去年。 您将如何使用 bash 判断目录中是否存在特定扩展名
我正在开发转换器服务,我使用 FFMPEG 转换视频。 我想检查输入文件,哪种真的是视频。 我使用以下命令并获取文件类型。但是如果文件已经被操作过就无法理解了: curl -s -o /dev/nul
我需要一个规则来添加 .html 扩展名,只要有“不”结尾的斜杠。 一个新客户最近更改了电子商务脚本,新版本以不同的方式处理 SEO,并更改了他们所有 16,000 多个产品链接。这在站点被重新索引之
我正在尝试使用 Kickstarter 进行扩展以覆盖页面的正常呈现,并呈现 PDF 文件。为此我使用 FPDF。但我不确定该怎么做。我尝试这样做,但没有成功: AddPage();
在寻找巴恩斯利蕨分形的实现时,我遇到了一个具有 .pde 扩展名的实现。哪种编程语言使用此扩展? Implementation Page 最佳答案 此代码来自Processing.org,一个基于Ja
Visual Studio Code (1.22.2) 提供了一个名为 .dockerfile 的文件扩展名。在保存对话框中。带有此扩展名的文件是什么? Dockerfile 包含在所有文档和示例中,
我正在为32位计算机编译一个应用程序,因为该应用程序的创建者将其设置为64位。我确保所有库和DLL都是32位的。但是,我在编译时遇到问题。当我使用sh make.sh进行编译时,当它进入GCC构建部分
当我将文件保存在 img/upload 文件夹中时,文件会以正确的文件扩展名保存。 但是,当我尝试下载该文件时,会附加一个 .htm 文件扩展名。 我怎样才能避免这种情况?我在下面添加了我的代码; V
GHC 有几种有用的语言 extensions用于机械派生各种常见的 Haskell 类型类(-XDeriveFunctor、-XDeriveFoldable、-XDeriveTraversable)
我是一名优秀的程序员,十分优秀!