PDA

View Full Version : QProcess use dos comand



damonlin
26th October 2008, 04:38
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,

however it can't work ... :confused:

I type in prmot windows and it works....

Should the environent set worng ??

Here is my code:

void D_DirView::removeFile(void)
{
if( m_Process )
delete m_Process;

m_Process = new QProcess(this);
QStringList arguments << "/Q/S" << "D:\\tmp";
m_Process->start( "RD", arguments )
}

JimDaniel
26th October 2008, 06:05
I don't know, but you could also write a recursive function to empty the dir, then delete it. I did this once:



void ResoModule::deleteSoundDir(const QString & dir)
{
QDir sound_dir(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());
}

wysota
26th October 2008, 10:28
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.


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.

chaoticbob
26th October 2008, 11:08
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.

damonlin
26th October 2008, 13:30
Thank you so much ~~

I'll implement just like what JimDaniel offer ~~