如何获取路径的正确大小写? [英] How do I get the correct case of a path?

查看:122
本文介绍了如何获取路径的正确大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小而痒的问题。

I have a small but itching problem. How do I get the correct case for a Windows path in Qt?

假设我有一个路径 c:\documents和settings \ wolfgang \documents 存储在 QString str ,我想知道正确的情况,这里 C:\Document和Settings\Wolfgang\Documents QDir(str).absolutePath()不给我正确的路径。

Let's say i have a path c:\documents and settings\wolfgang\documents stored in a QString str and i want to know the correct case, here C:\Document and Settings\Wolfgang\Documents. QDir(str).absolutePath() doesn't get me the path with correct case.

因为我没有任何线索可以尝试什么呢?

Any suggestions, since I have no clue what else i could try?

谢谢您的时间!

推荐答案

没有一个简单的方法来做到这一点,但你可以尝试做一个QDir.entryList,然后对结果做一个不区分大小写的搜索。这将为您提供正确的文件名。然后,您需要为该结果获取 absolutePath

There isn't a simple way to do this, but you can try doing a QDir.entryList, and then do a case insensitive search on the results. This will provide you with the correct filename. You'll then need to get the absolutePath for that result.

这将为您提供保留的路径/文件名。

This should give you the preserved-case for the path/filename.

这篇关于如何获取路径的正确大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆