我从 Qt GUI 将文件列表收集到 QStringList 中。这些文件中的每一个都是一个 .txt
文件,在 same_folder_as_txt/videos/
中有一个对应的视频文件。
有没有一种简单的方法可以将 QString 对象作为文件路径来操作?例如,给定 C:/some/path/foo.txt
,我想检索 C:/some/path/videos/foo.avi
最佳答案
将你的路径作为 QString
s
info = QFileInfo(s)
// Get the name of the file without the extension
base_name = info.baseName()
// Add a ".avi" extension
video_file = QStringList((base_name, "avi")).join(".")
// Get the directory
dir_name = info.path()
// Construct the path to the video file
video_path = QStringList((dir_name, QString("videos"), video_file).join("/")
关于c++ - 如何将 QString 视为文件位置并获取其目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12301484/