Point getOpenFileName to parent of current working directory
-
In getOpenFileName how do I get it to open the parent of the current working directory?
-
In getOpenFileName how do I get it to open the parent of the current working directory?
@Ed-Schneider Well, you pass that folder as const QString &dir = QString() parameter.
UseQDir::current() + "/.."
-
@Ed-Schneider Well, you pass that folder as const QString &dir = QString() parameter.
UseQDir::current() + "/.."
@jsulm said in Point getOpenFileName to parent of current working directory:
"/.."
Can you create an example of calling GetOpenFile Name pointing to the parent directory? I tried several variations and could not get it to work. I'm working in Python with PySide6 and Windows. Thanks
-
@jsulm said in Point getOpenFileName to parent of current working directory:
"/.."
Can you create an example of calling GetOpenFile Name pointing to the parent directory? I tried several variations and could not get it to work. I'm working in Python with PySide6 and Windows. Thanks
@Ed-Schneider
He did. UseQDir.current() + "/.."
or even just".."
, and pass that as the directory. -
@jsulm said in Point getOpenFileName to parent of current working directory:
"/.."
Can you create an example of calling GetOpenFile Name pointing to the parent directory? I tried several variations and could not get it to work. I'm working in Python with PySide6 and Windows. Thanks
@Ed-Schneider
try:QDir dir; dir.cdUp(); qDebug()<<dir.path();
-
@Ed-Schneider
try:QDir dir; dir.cdUp(); qDebug()<<dir.path();
@mpergand
That has the side-effect of permanently changing the application's current directory, just to open a file.
(Or does it only change the directory of thatQDir
instance? In any case, in the politest way, I don't see this would help, I don't thinkQFileDialog::getOpenFileName
takes aQDir
.)
Just passing the..
is all that is needed here. -
I got a working solution from ChatGPT -
current_directory = os.getcwd()
parent_directory = os.path.dirname(current_working_directory)and then use keyword dir=parent_directory in the call on getOpenFileName
-
I got a working solution from ChatGPT -
current_directory = os.getcwd()
parent_directory = os.path.dirname(current_working_directory)and then use keyword dir=parent_directory in the call on getOpenFileName
@Ed-Schneider Did you try just
dir=".."
? -
@Ed-Schneider Did you try just
dir=".."
?@JonB That does indeed work as well. Thanks
-
These days, pathlib is recommended:
from pathlib import Path
dir = Path.cwd().parentgetOpenFileName(... , os.fspath(dir), ....
-
These days, pathlib is recommended:
from pathlib import Path
dir = Path.cwd().parentgetOpenFileName(... , os.fspath(dir), ....
@friedemannkleint That does work as well. Glad you added this. This is what I will be using. Surprised this wasn't offered sooner. Danke.