I am compiling a list of files in a QStringList from the Qt GUI. Each of these files is a file .txtwith a corresponding video file in same_folder_as_txt/videos/.
.txt
same_folder_as_txt/videos/
Is there an easy way to manipulate QString objects as file paths? For example, given C:/some/path/foo.txtI want to getC:/some/path/videos/foo.avi
C:/some/path/foo.txt
C:/some/path/videos/foo.avi
You can convert them each to QDir, perform your modifications as a path, and then use absolutePath()to return QString.
QDir
absolutePath()
QString
Given your way as QString s
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("/")