From 2a3854db6bc3929341e4f19e538cc1a5b380fd8e Mon Sep 17 00:00:00 2001 From: xapantu Date: Fri, 2 Jul 2010 17:14:09 +0000 Subject: [PATCH] improve the checkandcreatedirectory recursive function file_manager using the stringutils split function git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5619 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/io/file_manager.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index f0532ae7c..f79db7745 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -384,23 +384,21 @@ bool FileManager::checkAndCreateDirectoryP(const std::string &path) if(m_file_system->existFile(io::path(path.c_str()))) return true; - - for(int i = 0; i <= path.size(); i++) + std::vector split = StringUtils::split(path,'/'); + std::string current_path =""; + for(unsigned int i=0; iexistFile(io::path(current_path.c_str()))) + std::cout << "The directory exist." << std::endl; + else { - std::string current_path = path.substr(0, i + 1); - std::cout << "Checking for: " << current_path << std::endl; - if(m_file_system->existFile(io::path(current_path.c_str()))) - std::cout << "The directory exist." << std::endl; - else + if(!checkAndCreateDirectory(current_path)) { - if(!checkAndCreateDirectory(current_path)) - { - fprintf(stderr, "Can't create dir '%s'", - current_path.c_str()); - break; - } + fprintf(stderr, "Can't create dir '%s'", + current_path.c_str()); + break; } } }