diff options
Diffstat (limited to 'rbutil/rbutilqt/utils.cpp')
-rw-r--r-- | rbutil/rbutilqt/utils.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/utils.cpp b/rbutil/rbutilqt/utils.cpp new file mode 100644 index 0000000000..c7c8371274 --- /dev/null +++ b/rbutil/rbutilqt/utils.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * __________ __ ___. + * 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); + QStringList list = dir.entryList(QDir::AllEntries); // make list of entries in directory + QFileInfo fileInfo; + QString curItem, lstAt; + for(int i = 0; i < list.size(); i++){ // loop through all items of list + QString name = list.at(i); + if(!(name == ".") && !(name == "..")){ + 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 +} |