Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# FilePath.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * ファイルパス実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "LampBasic.h"
    00026 #include "Core/InputOutput/FilePath.h"
    00027
    00028 namespace Lamp{
    00029
    00030 //------------------------------------------------------------------------------
    00031 // 名前の取得
    00032 String FilePath::getName() const{
    00033     String fileName = getFileName();
    00034     int lastDotIndex = fileName.getLastIndexOf('.');
    00035     if(lastDotIndex != -1){
    00036         fileName = fileName.getSubstring(0, lastDotIndex);
    00037     }
    00038     return fileName;
    00039 }
    00040 //------------------------------------------------------------------------------
    00041 // ファイル名の取得
    00042 String FilePath::getFileName() const{
    00043     int dirIndex = path_.getLastIndexOf("/");
    00044     int enIndex = path_.getLastIndexOf("\\");
    00045     if(dirIndex < enIndex){ dirIndex = enIndex; }
    00046     String fileName = path_;
    00047     if(dirIndex != -1){
    00048         fileName = path_.getSubstring(dirIndex + 1);
    00049     }
    00050     return fileName;
    00051 }
    00052 //------------------------------------------------------------------------------
    00053 // 拡張子の取得
    00054 String FilePath::getExtension() const{
    00055     String extension;
    00056     int lastDotIndex = path_.getLastIndexOf('.');
    00057     if(lastDotIndex != -1){
    00058         extension = path_.getSubstring(lastDotIndex + 1);
    00059     }
    00060     return extension.getLowerCase();
    00061 }
    00062 //------------------------------------------------------------------------------
    00063 // フォルダパスの取得
    00064 String FilePath::getFolderPath() const{
    00065     String folderPath;
    00066     int dirIndex = path_.getLastIndexOf("/");
    00067     int enIndex = path_.getLastIndexOf("\\");
    00068     if(dirIndex < enIndex){ dirIndex = enIndex; }
    00069     if(dirIndex != -1){
    00070         folderPath = path_.getSubstring(0, dirIndex + 1);
    00071     }
    00072     return folderPath;
    00073 }
    00074 //------------------------------------------------------------------------------
    00075 // ファイルが存在するか
    00076 bool FilePath::existFile() const{
    00077     FILE* file = fopen(path_.getBytes(), "rb");
    00078     if(file == NULL){ return false; }
    00079     fclose(file);
    00080     return true;
    00081 }
    00082 //------------------------------------------------------------------------------
    00083 } // End of namespace Lamp
    00084 //------------------------------------------------------------------------------