Solved How can I concatenate absolute path with relative path?
-
Hi,
Is there any function in QDir that allow us to concatenate 2 path (one is direct path and the other one is relative)
For example:
path 1 is "C:/home/user1/project/data"
path 2 is : "../data2/file.txt"
the result should be a String equal to "C:/home/user1/project/data2/file.txt"
I tried: QString finalPath = QDir("C:/home/user1/project/data").filePath("../data2/file.txt");
but it is not working .please help me
-
C:/home/user1/project/data/../data2/file.txt is same as C:/home/user1/project/data2/file.txt So you can simply append one path at the end of the other one.
-
C:/home/user1/project/data/../data2/file.txt is same as C:/home/user1/project/data2/file.txt So you can simply append one path at the end of the other one.
-
@jsulm Thank you I can use the result directly to parse the file later but if I want to show the result I want this one "C:/home/user1/project/data2/file.txt".
I thought there is a function like .join in python which allow us to concatenate 2 paths .
Thank you so much for your feedback it really helps me
-
@Mery_lamb Try https://doc.qt.io/qt-5/qdir.html#cleanPath with joined path C:/home/user1/project/data/../data2/file.txt