Solved QT Creator - QDir
-
@mrjj To be honest. I don't know how to escape it. This is what I need.
FMC_dir = C:\Users\Hassan\AppData\Local\FiveM\FiveM.app\cache
"rmdir "+ FMC_dir + "/priv /q /s "
I need text written to the bat to be like this
"C:\Users\Hassan\AppData\Local\FiveM\FiveM.app\cache\priv"
In quotes or the bat doesn't work.
Thanks -
well its just
\" something like stream << "rmdir " << "\"" << FMC_dir << "/priv" << "\"" << "/q /s "; or QString quote = "\""; "rmdir "+ quote +FMC_dir + "/priv"+quote + "/q /s "
-
@mrjj That works but I forgot to add, the /priv is a part of the path. Would I do this?
ccache << "rmdir " << """ << FMC_dir << """ << "priv /q /s " << "\n"; -
@FreeHassan29
just saw that."rmdir "+ quote +FMC_dir + "/priv"+quote + "/q /s " stream << "rmdir " << "\"" << FMC_dir << "/priv" << "\"" << "/q /s ";
-
@mrjj That's perfect. Thank you very much. Last question while I have your attention, would I use QProcess to launch this bat, and would QProcess work for creating another button to launch an application and connect to an IP?
-
@FreeHassan29
Yes you can use QProcess to launch a bat file but you must use the /C
parameterprocess.setProgram( "cmd.exe" ); // we need this to run the bat process.setArguments( { "/C", " E:\\deleteme.bat" ); // notice the /C
Notice sample uses startDetached. you dont need that.
https://stackoverflow.com/questions/51740460/execute-batch-file-with-qt-as-a-new-processand yes, you can simply use QProcess to launch other app. (cmd.exe and /C not needed for that)
-
@mrjj
Thank you very much. If I didn't specify a directory because I wanted the bat to be in the same folder as the bat file what would I do. I tried it but it doesn't seem to be executing the bat.
QProcess process;
process.setProgram( "cmd.exe" ); // we need this to run the bat
process.setArguments( { "/C", "ClearCache.bat"} ); // notice the /C
Stack overflow is down right now -
@FreeHassan29
Hi
you have to use full path to the bat file or else it can find it.
When your programs runs, the current folder is most likely inside the build folder.
You can use
qApp->applicationDirPath(); to say "where .exe" is
and place bat file there.
also the code you shown is not complete
need to call start or startDetached.sample from SO
QProcess process; process.setProgram( "cmd.exe" ); process.setArguments( { "/C", R"(E:\deleteme.bat)" } ); process.setWorkingDirectory( R"(E:\)" ); process.setStandardOutputFile( QProcess::nullDevice() ); process.setStandardErrorFile( QProcess::nullDevice() ); process.startDetached();
-
@mrjj It worked without me having to set the path. I just used the filename like this.
QProcess process;
process.setProgram( "cmd.exe" ); // we need this to run the bat
process.setArguments( { "/C", "ClearCache.bat"} ); // notice the /C
process.startDetached();It only ran because I used start detached
-
Ok super. :)