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
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
Actually I said that it deletes all the Files that are in the folders , and empty folders are left.....,
eg..
If there is a folder name "dir1" it further contains files(F1 , F2) and folder dir2.
then F1 and F2 are deleted but empty dir1 and dir2 folders are left....
My question is how can i delete empty folders?
Thanx
Always Believe in Urself
Merry
But you messed up the code.
In the case you run into a directory:
Qt Code:
dir.rmdir(subDir);To copy to clipboard, switch view to plain text mode
You removed that.
It should work, as long as the directory is not used/empty.
Couldn't you debug it to see exactly what is wrong?
Qt Code:
dir.rmdir(subDir);To copy to clipboard, switch view to plain text mode
Are u sure it works..
The function is like this only...
QDir::rmdir ( const QString & dirName )
and subDir is of QDir type...
and parameters passed in the function are of QString type...
Thanx
Always Believe in Urself
Merry
Bookmarks