PDA

View Full Version : Delete Directory



AnithaRagupathy
26th October 2007, 13:14
hi ,
I want to delete a directory empty or not empty in a easier way.
I dont want to use loop to iterate through the files and delete one by one.

high_flyer
26th October 2007, 13:17
...

Ok sorry, you wanted empty or not...

marcel
26th October 2007, 13:19
I want to delete a directory empty or not empty in a easier way.

So, rmdir won't work in this case.
See QDir::entryList() for a list of files and dirs. You need a recursive function to traverse the directory hierarchy and delete the files one by one.

jpn
26th October 2007, 13:20
hi ,
I want to delete a directory empty or not empty in a easier way.
I dont want to use loop to iterate through the files and delete one by one.
There is no other way around. Qt has no "rm -rf", only "rmdir". See http://www.qtcentre.org/forum/p-recursive-removal-of-dirs-post45687/postcount2.html.

high_flyer
26th October 2007, 13:31
May be QProcess with system specific call such as "rm" with "-R -d".
I guess windows has something similar too.

AnithaRagupathy
26th October 2007, 13:41
I m a beginner.Plz bear with me.but how to use QProcess to delete directory.

high_flyer
26th October 2007, 13:47
QProcess
I haven't used QProcess with Qt4 yet, but I can remember having some problems with Qt3 with some shell commands and arguments for those commands.
However I can't see anything in the docs that points any such problems in Qt4, so it might work.
If QProcess wont help you, you can try also system specific calls such as system().

AnithaRagupathy
26th October 2007, 13:55
i didnt understand ...How this QProcess can be used to delete directory?

high_flyer
26th October 2007, 14:00
You will have to READ the QProcess doc for that.
Ask if there is anything specific you don't understand.

marcel
26th October 2007, 15:20
Using Qprocess to delete a directory is a dirty and non-portable method.
It is better to use the filesystem API in Qt to do it.