rockbox/rbutil/rbutilqt/utils.cpp
Dominik Riebeling abd8c39a4d Code police and simplify function a bit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15089 a1c6a512-1295-4272-9138-f99709370657
2007-10-12 16:54:51 +00:00

44 lines
1.7 KiB
C++

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id$
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "utils.h"
#include <QDir>
// recursive function to delete a dir with files
bool recRmdir( const QString &dirName )
{
QString dirN = dirName;
QDir dir(dirN);
// make list of entries in directory
QStringList list = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
QFileInfo fileInfo;
QString curItem, lstAt;
for(int i = 0; i < list.size(); i++){ // loop through all items of list
QString name = list.at(i);
curItem = dirN + "/" + name;
fileInfo.setFile(curItem);
if(fileInfo.isDir()) // is directory
recRmdir(curItem); // call recRmdir() recursively for deleting subdirectory
else // is file
QFile::remove(curItem); // ok, delete file
}
dir.cdUp();
return dir.rmdir(dirN); // delete empty dir and return if (now empty) dir-removing was successfull
}