Hi Marcel
Really I tried it lots & lots of times but it does not remove directories,It removes all the files but not directories .
Ok Pls view my code , and tell me is I m doin something wrong.
Qt Code:
{ if (dirPath.exists()) { QList<QFileInfo> infLst = dirPath.entryInfoList(); for(int i=0;i<infLst.size();i++) { if(!(strFileInfo.fileName() == "." || strFileInfo.fileName() == "..")) { if(strFileInfo.isDir()) { DeleteData(strFilePath); } else { unsigned char *pBuff; FILE *fh = NULL; long SizeToRead =fileName.size(); fh=fopen((const char*)fileName.toAscii() ,"wb+"); pBuff = new unsigned char[SizeToRead]; QString str; str = comboBox->itemText(comboBox->currentIndex()); bool ok; int val= str.toInt(&ok,36); memset(pBuff,val,SizeToRead); fwrite((void*)pBuff,SizeToRead,1,fh); delete []pBuff; pBuff=NULL; fclose(fh); file1.remove(); } } } dirPath.cdUp(); dirPath.rmdir(dirViewPath); } }To copy to clipboard, switch view to plain text mode
Thanx
Always Believe in Urself![]()
Merry
But I really wanted to know where you call DeleteData.
Could you post that part of the code?
Regards
Hi..
I m sending u both .h and .cpp files Pls view this code.
Form1.h
Qt Code:
{ Q_OBJECT public: { setupUi(this); connect(File,SIGNAL(clicked()),this,SLOT(ShowFileDialog())); connect(Erase,SIGNAL(clicked()),this,SLOT(CallDeleteData())); }; private slots: void ShowFileDialog(); void CallDeleteData(); protected: QString m_file; };To copy to clipboard, switch view to plain text mode
Form1.cpp
Qt Code:
void Form1::ShowFileDialog() { "/home", filename->setText(m_file); } void Form1::CallDeleteData() { DeleteData(m_file); } //////////////////////////////////////////////////////////////////////// /*Function for erasing*/ { if (dirPath.exists()) { QList<QFileInfo> infLst = dirPath.entryInfoList(); for(int i=0;i<infLst.size();i++) { if(!(strFileInfo.fileName() == "." || strFileInfo.fileName() == "..")) { if(strFileInfo.isDir()) { DeleteData(strFilePath); //recursive Calling } else { unsigned char *pBuff; FILE *fh = NULL; long SizeToRead =fileName.size(); fh=fopen((const char*)fileName.toAscii() ,"wb+"); pBuff = new unsigned char[SizeToRead]; QString str; str = comboBox->itemText(comboBox->currentIndex()); bool ok; int val= str.toInt(&ok,36); memset(pBuff,val,SizeToRead); fwrite((void*)pBuff,SizeToRead,1,fh); delete []pBuff; pBuff=NULL; fclose(fh); file1.remove(); } } } dirPath.cdUp(); dirPath.rmdir(dirViewPath); } }To copy to clipboard, switch view to plain text mode
Last edited by merry; 30th July 2007 at 09:56. Reason: updated contents
Always Believe in Urself![]()
Merry
In CallDeleteData():
Also, remove lines 60 and 61 from DeleteData. They are not needed anymore.Qt Code:
void Form1::CallDeleteData() { DeleteData(m_file); if( dir.cdUp() ) { dir.rmdir(m_file); } }To copy to clipboard, switch view to plain text mode
Regards
Thanx Marcel for the reply.
I tried it , but directories are still there..
DeleteData function is recursively Calling.....
Thanx...
Always Believe in Urself![]()
Merry
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
Here it is. I just tested it:
This is where it starts( the wrapper):
Qt Code:
void qttest::clearAll() { clearAll(dirRoot); d.cdUp(); d.rmdir(dirRoot); }To copy to clipboard, switch view to plain text mode
This is the actual function:
Qt Code:
{ { if(finfo.isDir() ) { clearAll(finfo.absoluteFilePath()); dir.rmdir(finfo.absoluteFilePath()); } else { //file dir.remove(finfo.absoluteFilePath()); } } }To copy to clipboard, switch view to plain text mode
Regards.
Hi Marcel
Can u pls tell me in function
Qt Code:
void qttest::clearAll() { clearAll(dirRoot); d.cdUp(); d.rmdir(dirRoot); }To copy to clipboard, switch view to plain text mode
Why you used this(4th line of the above code) that is:
Thanx
Always Believe in Urself![]()
Merry
You should pass there the directory returned by the file dialog.
clearAll() without any parameters is just an overloaded variant of the second, provided for convenince.
It is really not that different than the first version.
I just passed a folder that I created on my hard disk.
And don't say it doesn't work because it does. If you don't mess up the code, then it will work for you too.
Regards
Hi Marcel
Thanx Marcel for helping me so much
Pls dont get angry on me....
I think I am not messing the code now , It is same as the code u sent to me , Is'nt it...
But it also deletes the files but not folders.....
Qt Code:
void Form1::ShowFileDialog() { "/home", filename->setText(m_file); } void Form1::DeleteData() { QString dirRoot = m_file; DeleteData(dirRoot); d.cdUp(); d.rmdir(dirRoot); } //////////////////////////////////////////////////////////////////////// /*Function for erasing*/ { if (dirPath.exists()) { QList<QFileInfo> infLst = dirPath.entryInfoList(); for(int i=0;i<infLst.size();i++) { if(!(strFileInfo.fileName() == "." || strFileInfo.fileName() == "..")) { if(strFileInfo.isDir()) { DeleteData(strFileInfo.absoluteFilePath()); dirPath.rmdir(strFileInfo.absoluteFilePath()); } else { dirPath.remove(strFileInfo.absoluteFilePath()); } } } } }To copy to clipboard, switch view to plain text mode
Thanx
Always Believe in Urself![]()
Merry
Are you sure you have permissions to delete the directories?
Are you running as root or as a normal user?
I m running as a normal user
Always Believe in Urself![]()
Merry
Well, could you try running it as root?
I tried it running as a root
It works , but for that directories only which contains files only.
not for that directories which contains both files and folders ..
Thanx
Always Believe in Urself![]()
Merry
Sorry, but can't help you. I really can't understand what's going on.
I tested it on the following structure. Every directory in there had 1,2 or three files in it.
So I can't say what is going on in your case.
Regards
merry (30th July 2007)
Bookmarks