⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filename.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
bool ecFileName::Exists     () const{    return IsFile() || IsDir() ;}bool ecFileName::IsDir      () const{    return wxPathExists(* this);}bool ecFileName::IsFile     () const{#if defined(__WXMAC__)    struct stat stbuf;    if (filename && stat (wxUnix2MacFilename(filename), &stbuf) == 0 )        return TRUE;    return FALSE ;#else    wxStructStat st;    if ((*this) != wxT("") && wxStat (wxFNSTRINGCAST fn_str(), &st) == 0 && (st.st_mode & S_IFREG))        return TRUE;    return FALSE;#endif}bool ecFileName::IsReadOnly () const{#ifdef __WXMSW__    long a=GetFileAttributes(* this); return 0xFFFFFFFF!=a && (0!=(a&FILE_ATTRIBUTE_READONLY ));#else    wxFAIL_MSG("ecFileName::IsReadOnly not supported on this platform.");    return FALSE;#endif}bool ecFileName::SameFile(const ecFileName &o) const{#ifdef __WXMSW__    return 0==ShortName().CmpNoCase(o.ShortName());#else    // On most other platforms, case is important.    return o == (*this);#endif}ecFileName ecFileName::ExpandEnvironmentStrings(const wxChar* psz){    // wxExpandEnvVars is from confbase.h    ecFileName f = wxExpandEnvVars(psz);    return f;}const ecFileName& ecFileName::ExpandEnvironmentStrings(){    *this=ecFileName::ExpandEnvironmentStrings(*this);    return *this;}#if 0// Helper for Relative()  psz is in full format.ecFileName ecFileName::Drive(const wxChar* psz){    if(wxIsalpha(psz[0])){        return psz[0];    } else if(cSep==psz[0]&&cSep==psz[1]){        wxChar *c=_tcschr(psz+2,cSep);        if(c){            c=_tcschr(c+1,cSep);            if(c){                return wxString(psz,c-psz);            }        }    }    return _T("");}#endifecFileName ecFileName::Relative(const wxChar* compare,const wxChar* current){#ifdef __WXMSW__    wxString rc;    bool b=(TRUE==PathRelativePathTo(rc.GetWriteBuf(1+MAX_PATH),current,FILE_ATTRIBUTE_DIRECTORY,compare,0));    rc.UngetWriteBuf();    return b?(ecFileName)rc:(ecFileName)compare;#else    wxFAIL_MSG("ecFileName::Relative not implemented on this platform.");    return ecFileName();#endif} const ecFileName& ecFileName::MakeRelative(const wxChar* pszRelativeTo){    *this=ecFileName::Relative(*this,pszRelativeTo);    return *this;}ecFileName ecFileName::GetCurrentDirectory(){    ecFileName f;    f = wxGetCwd();    f.Normalize();    return f;}const ecFileName& ecFileName::Append(const wxChar* lpsz){    if (lpsz)        return *this;    //wxString::ConcatInPlace(lpsz);    wxString::Append(lpsz);    return *this;    }const ecFileName& ecFileName::Append(wxChar ch){    ConcatInPlace(wxString(ch));    return *this;}bool ecFileName::IsAbsolute() const{    int nLength=Len();    const wxString& psz=*this;    return         (nLength>0 && (cSep==psz[0]))|| // starts with '\'        (nLength>1 && (        (wxIsalpha(psz[0]) && wxTChar(':')==psz[1]) ||  // starts with [e.g.] "c:\"        (cSep==psz[0] && cSep==psz[1])));              // UNC}// TODO (?)#if 0// Return an array of filename pieces.  Plugs '\0's into 'this', which// is therefore subsequently only usable as referenced by the returned array.const wxChar* *ecFileName::Chop(){    wxChar *c;    // Count the separators    int nSeps=0;    for(c=_tcschr(m_pchData,cSep);c;c=_tcschr(c+1,cSep)){        nSeps++;    }    const wxChar* *ar=new const wxChar*[2+nSeps]; // +1 for first, +1 for terminating 0    ar[0]=m_pchData;    int i=1;    for(c=_tcschr(m_pchData,cSep);c;c=_tcschr(c+1,cSep)){        ar[i++]=c+1;        *c=wxTChar('\0');    }    ar[i]=0;    return ar;}#endifecFileName ecFileName::GetTempPath(){    ecFileName f;#ifdef __WXMSW__#ifdef _UNICODE    ::GetTempPathW(1+MAX_PATH,f.GetWriteBuf(1+MAX_PATH));#else    ::GetTempPathA(1+MAX_PATH,f.GetWriteBuf(1+MAX_PATH));#endif  f.UngetWriteBuf();#elif defined(__WXGTK__)#else    wxFAIL("ecFileName::GetTempPath() not implemented on this platform.");#endif    f.Normalize();    return f;    }const ecFileName ecFileName::CygPath () const {#ifdef __WXMSW__    ecFileName rc = ShortName();    if(wxIsalpha(rc[(size_t)0]) && wxTChar(':')==rc[(size_t)1])    {        // Convert c:\ to /cygdrive/c/        wxString s = wxString(wxT("/cygdrive/")) + wxString(rc[(size_t)0]) + rc.Mid(2);        rc = s;    }    size_t i;    for (i = 0; i < rc.Len(); i++)    {        if (rc[i] == wxTChar('\\'))            rc[i] = wxTChar('/');    }#else    const ecFileName& rc = * this;#endif    return rc;}bool ecFileName::CreateDirectory(bool bParentsToo,bool bFailIfAlreadyExists) const{    if(bParentsToo)    {        // Create intermediate directories        // 'rest' will progressively have its separators replaced by underscores in order        // to find the next separator        wxString rest = * this;        size_t lastPos = 0;        int len = rest.Len();#ifdef __WXMSW__        // If the path is a network path, ignore the first part of the path        if (len > 2 && (rest.GetChar(0) == wxT('\\') || rest.GetChar(0) == wxT('/')) && (rest.GetChar(1) == wxT('\\') || rest.GetChar(1) == wxT('/')))        {            rest.SetChar(0,wxT('_')); rest.SetChar(1,wxT('_'));            lastPos = rest.Find(cSep);            if (lastPos != -1 && lastPos >= 0)                rest.SetChar(lastPos,wxT('_'));        }#endif                while (lastPos != -1)        {            lastPos = rest.Find(cSep);            if (lastPos != -1 && lastPos >= 0)            {                rest[lastPos] = wxT('_'); // So we find the NEXT separator                // don't attempt to create "C: or /"                if (lastPos > 0 && (*this)[lastPos-1] == wxT(':'))                    continue;                else if (lastPos == 0)                    continue;            }            // Fail if any of the dirs exist already            wxString str(this->Mid(0, lastPos));            bool alreadyExists = wxDirExists(str);            if (alreadyExists && bFailIfAlreadyExists)                return FALSE;                        if (!alreadyExists)                if (!wxMkdir(str))                    return FALSE;        }    }    return IsDir()? (!bFailIfAlreadyExists) : (TRUE==wxMkdir(*this));}const wxString ecFileName::Extension() const{    wxString path, name, ext;    wxSplitPath(*this, & path, & name, & ext);    return ext;}const wxString ecFileName::Root() const{    return wxPathOnly(*this);}ecFileName ecFileName::SetCurrentDirectory(const wxChar* pszDir){    const ecFileName strPwd=wxGetCwd();    if (::wxSetWorkingDirectory(pszDir))        return strPwd;    else        return wxT("");}bool ecFileName::RecursivelyDelete(){    wxArrayString ar;    int i;    for(i=FindFiles(*this,ar)-1;i>=0;--i){        wxRemoveFile(ar[i]);    }    for(i=FindFiles(*this,ar,wxT("*.*"),TRUE,0)-1;i>=0;--i){        wxRmdir(ar[i]);    }    return TRUE==wxRmdir(*this);}// TODO: take account of dwExcludeint ecFileName::FindFiles (const wxString& pszDir,wxArrayString &ar,const wxString& pszPattern/*=wxT("*.*")*/,bool bRecurse/*=TRUE*/,long dwExclude/*=wxDIR_DIRS|wxDIR_HIDDEN*/){    ar.Clear();    // Scoping for wxDir    {        wxDir dir(pszDir);                wxString fileName;        bool bMore = dir.GetFirst(& fileName, pszPattern, wxDIR_FILES);        while (bMore)        {            if (fileName != wxT(".") && fileName != wxT(".."))            {                // Add full path                ecFileName path(pszDir);                path += (const wxChar*) fileName;                ar.Add(path);            }            bMore = dir.GetNext(& fileName);        }    }    if (bRecurse)    {        // Since wxDir isn't rentrant, we need to gather all the directories        // first        wxArrayString ar2;        // Scoping        {            wxDir dir(pszDir);                        wxString fileName;                        bool bMore = dir.GetFirst(& fileName, wxT("*"), wxDIR_DIRS);            while (bMore)            {                if (fileName != wxT(".") && fileName != wxT(".."))                {                    // Add full path                    ecFileName path(pszDir);                    path += (const wxChar*) fileName;                    ar2.Add(path);                }                bMore = dir.GetNext(& fileName);            }        }        unsigned int i;        for (i = 0; i < ar2.Count(); i++)        {            wxString f(ar2[i]);            FindFiles(f, ar, pszPattern, bRecurse, dwExclude);        }    }    return ar.Count();}void ecFileName::ReplaceExtension(const wxString& newExt){    wxString ext = newExt;    if (ext[(unsigned) 0] == wxT('.'))        ext = ext.Mid(1);    wxStripExtension(* this);    this->wxString::Append(wxT("."));    this->wxString::Append(ext);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -