Re: QProcess use dos comand
I don't know, but you could also write a recursive function to empty the dir, then delete it. I did this once:
Code:
void ResoModule
::deleteSoundDir(const QString & dir
) {
//First delete any files in the current directory
QFileInfoList files
= sound_dir.
entryInfoList(QDir::NoDotAndDotDot |
QDir::Files);
for(int file = 0; file < files.count(); file++)
{
sound_dir.remove(files.at(file).fileName());
}
//Now recursively delete any child directories
QFileInfoList dirs
= sound_dir.
entryInfoList(QDir::NoDotAndDotDot |
QDir::Dirs);
for(int dir = 0; dir < dirs.count(); dir++)
{
deleteSoundDir(dirs.at(dir).absoluteFilePath());
}
//Finally, remove empty parent directory
sound_dir.rmdir(sound_dir.path());
}
Re: QProcess use dos comand
Quote:
Originally Posted by
damonlin
Hi everyone,
Because QT's rmdir can't really remove the directory which is not empty ,
therefore, i choose to use QPrcess to execute dos coommand "RD" on windows,
Baaaaaad idea, because of many reasons. Do it as suggested in the other post.
Quote:
however it can't work ... :confused:
I type in prmot windows and it works....
Should the environent set worng ??
There is no such thing as "dos command". It's a "command.com command" thus you need to invoke it through command.com instead of calling it directly. There is no binary rd.com on your system, right? So QProcess can't find it.
Re: QProcess use dos comand
If you really want to do it the way that you have it - you can probably do via /C for cmd.exe ( cmd /c "rd /q /s whatever" ) and spawn that instead of trying to spawn the nonexistent RD. Putting a /? after cmd in a command prompt will show you all the options available.
But be warned, as wysota mentioned. It's not a good idea.
Re: QProcess use dos comand
Thank you so much ~~
I'll implement just like what JimDaniel offer ~~