Hi all
Working on Qt4.2
Problem :
I want to delete all the flles and folders contained in the directory that is selected by QFileDialog.
Pls help , if anyboby know.......
Thanx
Hi all
Working on Qt4.2
Problem :
I want to delete all the flles and folders contained in the directory that is selected by QFileDialog.
Pls help , if anyboby know.......
Thanx
Always Believe in Urself
Merry
This code is not tested so you may have to polish it a bit .Qt Code:
{ QList<QFileInfo> infLst = dir.entryInfoList(); { if(fInfo.isDir() ) { recursiveDelete(subDir); dir.rmdir(subDir); } else { //file dir.remove(finfo.absolutePath()); } } }To copy to clipboard, switch view to plain text mode
But the idea is correct.
Regards
punkypogo (2nd June 2008)
You should specify QDir::NoDotAndDotDot. I.e.
you should also be very careful with this function. Otherwise you'll get into trouble faster than you can sayQt Code:
To copy to clipboard, switch view to plain text modeQt Code:
To copy to clipboard, switch view to plain text mode
merry (26th July 2007)
Thanx
It works , It deletes all the files contained in the folder,
but is there any other way , that after deleting all the files of the folder it also deletes that folder .
Thanx
Always Believe in Urself
Merry
Yes, just call rmdir for the original QDir, that you pass to the funciton.
You have to call this after the function returns.
Regards
Thanx
I do like this only ,but it wont works...
Pls view code...
Qt Code:
{ QList<QFileInfo> infLst = dirPath.entryInfoList(); for(int i=0;i<infLst.size();i++) { if(!(strFileInfo.fileName() == "." || strFileInfo.fileName() == "..")) { if(strFileInfo.isDir()) { DeleteData(strFilePath); dirPath.rmdir(dirViewPath); } else { file1.remove(); } } } }To copy to clipboard, switch view to plain text mode
Always Believe in Urself
Merry
DeleteData does not work?
Or removing the parent dir?
I assume you call it like this:
Qt Code:
... QString dirViewPath = ... DeleteData(dirViewPath); //Also add the following two lines: dir.rmdir(); ...To copy to clipboard, switch view to plain text mode
Or is it a slot?
Regards
HI
Pls view the code I sent you in the last post,I think I had added the above two lines..DeleteData does not work?
Or removing the parent dir?
I assume you call it like this:
...
QString dirViewPath = ...
DeleteData(dirViewPath);
//Also add the following two lines:
QDir dir(dirViewPath);
dir.rmdir();
thanx
Always Believe in Urself
Merry
Oh, yes, I see now.
That will not work because at that point the parent dir is possible not to be empty, therefore the call will fail.
Do it like I have shown you.
Another solution is:
Qt Code:
void Form1::DeleteData(String dirViewPath) { ... //function body ... if(!dirPath.count()==2) //"." and ".." -- might not be the case. if not,. test with 0 { dirPath.cdUp(); dirPath.rmdir(dirViewPath); } }To copy to clipboard, switch view to plain text mode
This will work. I forgot to mention that you have to go one level above dirViewPath, in order to delete it.
Regards
Thanx for the reply
can u pls explain me why u had used this line
and also I had used this also
Qt Code:
if(!dirPath.count()==2) //"." and ".." -- might not be the case. if not,. test with 0 { dirPath.cdUp(); dirPath.rmdir(dirViewPath); }To copy to clipboard, switch view to plain text mode
but it also not works....
Always Believe in Urself
Merry
I am at work and I write these in a hurry.
Remove the "!".
I added those because count might return 2 even if the dir is empty( 2 for . and .. ).
Regards
Thanx Marcel
But it also not works
Always Believe in Urself
Merry
This means that "." and ".." are ignore by count().
Compare with 0 instead of 2 and you'll get it done.
Regards
Sorry
It again not works
regards
Always Believe in Urself
Merry
Then just delete it outside the function after the directory's contents are all removed.
I think you don't "believe in urself" .
Regards
Thank You very much for telling me that
I dont beleive in myself
Always Believe in Urself
Merry
hi
Is there anybody Who tells me how to delete folders after the deletion of files..
Actually all the files contained in the folders are deleted but only the blank folders are left
how can i delete folders , pls help....
I used this also but nothing happens
Qt Code:
if(dirPath.count()==0) { dirPath.cdUp(); dirPath.rmdir(dirViewPath); }To copy to clipboard, switch view to plain text mode
Thanx
Always Believe in Urself
Merry
Do it "urself"!
Regards
Thanx Marcel for the reply
Ok I 'll do it myself only.
Always Believe in Urself
Merry
Bookmarks