//功能:获取当前目录 //参数:无 //返回值:string类型,获取的当前目录 string CXxwCppPub::GetCurrentDir() { char buffer[_MAX_PATH ]; //memset(buffer,0,256); _getcwd(buffer, _MAX_PATH ); //需要头文件#include <direct.h> string sDir(buffer); return sDir; }
CString CFile::GetDir() const { CString sDir(m_sLongName); while (!sDir.empty() && !sDir.EndsWith("/") && !sDir.EndsWith("\\")) { sDir.RightChomp(); } return sDir; }
CString CFile::GetDir() const { CString sDir(m_sLongName); while (!sDir.empty() && sDir.Right(1) != "/" && sDir.Right(1) != "\\") { sDir.RightChomp(); } return sDir; }
wxString CVolume::GetPathPrefix(const wxString &_sDir) { wxString sDir(_sDir); wxString sBase = nwxFileUtil::BaseName(sDir); nwxFileUtil::EndWithSeparator(&sDir); sDir.Append(sBase); sDir.Append(wxChar('_')); return sDir; }
NoString NoFile::GetDir() const { NoString sDir(m_longName); while (!sDir.empty() && !sDir.endsWith("/") && !sDir.endsWith("\\")) { sDir.rightChomp(1); } return sDir; }
wxString nwxFileUtil::BaseName(const wxString &_sDir) { wxString sDir(_sDir); NoEndWithSeparator(&sDir); wxString sRtn; size_t nLen = sDir.Len(); if(nLen) { wxFileName fn(sDir); sRtn = fn.GetFullName(); } return sRtn; }
void wxFileDialog::GetPaths ( wxArrayString& rasPaths ) const { wxString sDir(m_dir); size_t nCount = m_fileNames.GetCount(); rasPaths.Empty(); if (m_dir.Last() != _T('\\')) sDir += _T('\\'); for ( size_t n = 0; n < nCount; n++ ) { rasPaths.Add(sDir + m_fileNames[n]); } } // end of wxFileDialog::GetPaths
/** * @brief 删除目录 * @param[in] szDir 路径 * @param[in] bContinueWhenFail 删除某个文件失败时,是否继续 * @return 成功返回TRUE,失败返回FALSE * @see */ static BOOL DeleteDirectory(LPCTSTR lpDir, BOOL bContinueWhenFail = TRUE) { if (!lpDir) return FALSE; BOOL bReturn = FALSE; CString sDir(lpDir); CString sFindPath; WIN32_FIND_DATA fData; HANDLE hFind = INVALID_HANDLE_VALUE; ZLPath::PathAddBackslash(sDir); sFindPath.Format(_T("%s*.*"), sDir); hFind = ::FindFirstFile(sFindPath, &fData); if (hFind == INVALID_HANDLE_VALUE) goto Exit0; do { if (0 == _tcscmp(fData.cFileName, _T(".")) || 0 == _tcscmp(fData.cFileName, _T(".."))) continue; if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { CString sSubfolder; sSubfolder.Format(_T("%s%s\\"), sDir, fData.cFileName); if ((FALSE == DeleteDirectory(sSubfolder, bContinueWhenFail)) && (!bContinueWhenFail)) goto Exit0; } else { CString sFileName = fData.cFileName; sFileName.MakeLower(); if ((FALSE == ::DeleteFile(sDir + sFileName)) && (!bContinueWhenFail)) goto Exit0; } } while (::FindNextFile(hFind, &fData) != 0); bReturn = TRUE; Exit0: if (hFind != INVALID_HANDLE_VALUE) ::FindClose(hFind); ::RemoveDirectory(sDir); ZLPath::PathRemoveBackslash(sDir); ::RemoveDirectory(sDir); return bReturn; }
int FileMgr::copyDir(const char *srcDir, const char *destDir) { int retVal = 0; if (auto dir = DirectoryEnumerator(srcDir)) { std::string sDir(std::string(srcDir) + '/'); std::string dDir(std::string(destDir) + '/'); while (auto const ent = dir.readEntry()) { if (retVal) break; std::string const srcPath(sDir + ent); std::string const destPath(dDir + ent); if (!isDirectory(srcPath)) { retVal = copyFile(srcPath.c_str(), destPath.c_str()); } else { retVal = copyDir(srcPath.c_str(), destPath.c_str()); } } } return retVal; }
void CDirEntry::CleanupFiles() { wxFileName fn(m_sOutputFile); wxString sDir(fn.GetPath()); size_t nLenDir = sDir.Len(); size_t nLenParent = m_sOutputDir.Len(); if( (nLenDir >= nLenParent) && (nLenParent > 4) && nwxString::FileNameStringEqual( sDir.Mid(0,nLenParent),m_sOutputDir) ) { nwxKillDir::KillAfterStatic(sDir,false,m_dtStart); } #ifdef __WXDEBUG__ else { wxASSERT_MSG(0,"Problem matching directory names"); } #endif }
void CameraScreen::reinit() { Camera::reinit(); // find the position of the center of the screen in 3D space this->centerScreen = position + (screenDist * direction); double cosrot = cos(rotation); double sinrot = sin(rotation); // compute the directions of the u and v vector along the screen P3S sDir(direction); P3S sdu(P3(cosrot,0.0,sinrot)); P3S sdv(P3(sinrot,0.0,cosrot)); sdu.u += sDir.u + M_PI/2; sdv.v += sDir.v; P3 du(sdu); P3 dv(sdv); du.normalize(); dv.normalize(); // deduce dx and dy this->dx = du; this->dy = - dv; // precompute the top left corner of the screen int width = screen->getWidth(); int height = screen->getHeight(); this->topLeftCornerScreen = centerScreen - ((width/2)*dx) - ((height/2)*dy); }
//--------------------------------------------------------------------------- // copyInstallFiles //--------------------------------------------------------------------------- void CDaliDeploymentEngine::copyInstallFiles(IPropertyTree& instanceNode, const char* destPath) { const char* computer = instanceNode.queryProp("@computer"); if ((m_deployFlags & DEFLAGS_CONFIGFILES) && computer && *computer) { // Create dalisds.xml is not already exists StringBuffer hostRoot(getHostRoot(computer, NULL)); const char* dir = m_process.queryProp("@dataPath"); if (!dir || !*dir) dir = instanceNode.queryProp("@directory"); if (dir) { if (isPathSepChar(*dir)) dir++; StringBuffer sDir( dir ); sDir.replace(':', '$'); sDir.replace('/', '\\'); sDir.insert(0, hostRoot.str()); if (!checkFileExists( sDir.str() )) { Owned<IPropertyTree> tree = &m_environment.getPTree(); StringBuffer xml("<SDS>"); toXML(tree, xml); xml.append("</SDS>"); sDir.append( "\\dalisds.xml" ); writeFile(sDir.str(), xml.str()); } } } // Copy install files to deploy subdir CDeploymentEngine::copyInstallFiles(instanceNode, destPath); }
void CIISConfigHelper::PopulateTreeFromFileSystem(CTreeCtrl& cTree, HTREEITEM htParent, const std::set<CStringW>& IgnoreDirNames, int nMaxDepth) { if (htParent == NULL) return; // get the item data from the tree item IISURIItem* pParentItem = (IISURIItem*) cTree.GetItemData(htParent); if (pParentItem == NULL) { ASSERT(pParentItem != NULL); return; } // if the item is incomplete then we need to get it's file system path if (pParentItem->Type == IISURIItem::IncompleteFileSystemPath && pParentItem->sFileSystemPath.GetLength() <= 0) { // get the grand parent item HTREEITEM htGrandParent = cTree.GetParentItem(htParent); if (htGrandParent == NULL) { ASSERT(htGrandParent != NULL); return; } // get the grand parent item data IISURIItem* pGrandParentItem = (IISURIItem*) cTree.GetItemData(htGrandParent); if (pGrandParentItem == NULL) { ASSERT(pGrandParentItem != NULL); return; } // the grand parent MUST not be incomplete if (pGrandParentItem->Type == IISURIItem::IncompleteFileSystemPath) { ASSERT(pGrandParentItem->Type != IISURIItem::IncompleteFileSystemPath); return; } // get the item name CStringW sName = CStringW(cTree.GetItemText(htParent)); if (sName.GetLength() <= 0) { ASSERT(sName.GetLength() > 0); return; } // make the path to the parent item CPathT<CStringW> ItemFileSystemPath(pGrandParentItem->sFileSystemPath); ItemFileSystemPath.Append(sName); // assign the new file system path and set the type pParentItem->sFileSystemPath = (LPCWSTR) ItemFileSystemPath; pParentItem->Type = IISURIItem::FileSystem; } // if the item already has children then we need to build up a list of their names std::set<CStringW> KnownDirs; if (cTree.ItemHasChildren(htParent) == TRUE) { // loop through all the children HTREEITEM htChild = cTree.GetChildItem(htParent); while (htChild != NULL) { // get the child name CStringW sName = CStringW(cTree.GetItemText(htChild)); // we need lower case so we can compare easier sName.MakeLower(); // add the name to the known list KnownDirs.insert(sName); // move on to the next child item htChild = cTree.GetNextSiblingItem(htChild); } } #ifdef _DEBUG ATLTRACE2(L"CIISConfigHelper::PopulateTreeFromFileSystem() : searching '%s'\n", pParentItem->sFileSystemPath); #endif // create a search string CPathT<CStringW> FileSystemPath(pParentItem->sFileSystemPath); FileSystemPath.Append(L"*.*"); CStringW sSearchPath = (LPCWSTR) FileSystemPath; // start the search WIN32_FIND_DATAW FindData; HANDLE hFind = ::FindFirstFileW(sSearchPath, &FindData); if (hFind == INVALID_HANDLE_VALUE) { // TODO: empty return; } CArray<CStringW, LPCWSTR> saDirs; // guess that we will have 32 sub dirs (the array will grow if we have more) saDirs.SetSize(32); // keep track of the number of dirs we have actually found int nDirsFound = 0; do { if ((FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) continue; // eliminate . and .. from the search if (FindData.cFileName[0] == '.') { if (FindData.cFileName[1] == '\0') { continue; } else if (FindData.cFileName[1] == '.' && FindData.cFileName[2] == '\0') { continue; } } // convert to lower case CStringW sTempFileName = FindData.cFileName; sTempFileName.MakeLower(); // only add to the collection if we don't already know about it if (KnownDirs.find(sTempFileName) != KnownDirs.end()) continue; // if it's a known ignore dir name - then ignore it if (IgnoreDirNames.find(sTempFileName) != IgnoreDirNames.end()) continue; #ifdef _DEBUG ATLTRACE2(L"CIISConfigHelper::PopulateTreeFromFileSystem() : found '%s'\n", FindData.cFileName); #endif saDirs.SetAtGrow(nDirsFound, FindData.cFileName); // we have found one nDirsFound++; } while (::FindNextFileW(hFind, &FindData) == TRUE); // get rid of the find handle ::FindClose(hFind); hFind = NULL; if (nDirsFound <= 0) { return; } if (nMaxDepth <= 0) { cTree.InsertItem(EmptyNodeString, htParent); return; } for (int i = 0; i < nDirsFound; i++) { CString sDir(saDirs[i]); HTREEITEM htChild = cTree.InsertItem(sDir, htParent); // create the child file system path CPathT<CStringW> FileSystemPath(pParentItem->sFileSystemPath); FileSystemPath.Append(saDirs[i]); // we need an item data for this tree item IISURIItem* pChildItem = new IISURIItem; pChildItem->Type = IISURIItem::FileSystem; pChildItem->sFileSystemPath = (LPCWSTR) FileSystemPath; // make the child URI CStringW sChildURI = pParentItem->sURI; int nChildURILength = sChildURI.GetLength(); if (nChildURILength > 0 && sChildURI[nChildURILength - 1] != '/') sChildURI += '/'; // append the dir name sChildURI += saDirs[i]; // assign the URI to the item data pChildItem->sURI = sChildURI; // store the item data cTree.SetItemData(htChild, (DWORD_PTR) pChildItem); PopulateTreeFromFileSystem(cTree, htChild, IgnoreDirNames, nMaxDepth - 1); } }
bool CGPX2SHP::On_Execute(void) { CSG_String sCmd; CSG_String sFile = Parameters("FILE")->asString(); CSG_String sBasePath = Parameters("BASEPATH")->asString(); CSG_String sShapefile; bool bWaypoints = Parameters("WAYPOINTS")->asBool(); bool bTrackpoints = Parameters("TRACKPOINTS")->asBool(); bool bRoutes = Parameters("ROUTES")->asBool(); bool bAdd = Parameters("ADD")->asBool(); CSG_Shapes *pShapes; sCmd = sBasePath + SG_T("\\gpx2shp "); if (bWaypoints) { sCmd += SG_T("-w "); }//if if (bTrackpoints) { sCmd += SG_T("-t "); }//if if (bRoutes) { sCmd += SG_T("-r "); }//if sCmd += sFile; system(sCmd.b_str()); if( bAdd ) { CSG_String sDir(SG_File_Get_Path(sFile)), sName(SG_File_Get_Name(sFile, false)); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_wpt"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_trk"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_rte"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); }//if return true; }//method
int main( int argc, char* argv[] ) { if ( argc != 6 ) { Mojo::Core::Printf( "Usage: DiceScoreCalculator.exe ground_truth_directory segmentation_directory width height num_images\n\nPress any key to exit." ); getchar(); return -1; } try { boost::filesystem::path gtDir( boost::filesystem::complete( argv[ 1 ] ) ); boost::filesystem::path sDir ( boost::filesystem::complete( argv[ 2 ] ) ); int width = boost::lexical_cast< int >( argv[ 3 ] ); int height = boost::lexical_cast< int >( argv[ 4 ] ); int numImages = boost::lexical_cast< int >( argv[ 5 ] ); RELEASE_ASSERT( boost::filesystem::exists( gtDir) ); RELEASE_ASSERT( boost::filesystem::is_directory( gtDir ) ); RELEASE_ASSERT( boost::filesystem::exists( sDir) ); RELEASE_ASSERT( boost::filesystem::is_directory( sDir ) ); RELEASE_ASSERT( width > 0 ); RELEASE_ASSERT( height > 0 ); RELEASE_ASSERT( numImages > 0 ); boost::filesystem::directory_iterator gtFile; boost::filesystem::directory_iterator sFile; gtFile = boost::filesystem::directory_iterator( gtDir ); sFile = boost::filesystem::directory_iterator( sDir ); int FP = 0; int TP = 0; int FN = 0; int TN = 0; for (; gtFile != boost::filesystem::directory_iterator(); ) { boost::filesystem::path gtFilePath( gtFile->path() ); boost::filesystem::path sFilePath( sFile->path() ); if ( boost::filesystem::is_regular_file( gtFilePath ) && boost::filesystem::is_regular_file( sFilePath ) ) { cv::Mat gtImage = cv::imread( gtFilePath.native_file_string() ); cv::Mat sImage = cv::imread( sFilePath.native_file_string() ); std::vector<cv::Mat> gtImageChannels; std::vector<cv::Mat> sImageChannels; cv::split( gtImage, gtImageChannels ); cv::split( sImage, sImageChannels ); cv::Mat gtImageR = gtImageChannels[2]; cv::Mat gtImageG = gtImageChannels[1]; cv::Mat gtImageB = gtImageChannels[0]; cv::Mat sImageR = sImageChannels[0]; for( int y = 0; y < height; y++ ) { for( int x = 0; x < width; x++ ) { if ( ( gtImageR.at< unsigned char >( y, x ) > 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == POSITIVE ( sImageR.at < unsigned char >( y, x ) >= 1 ) ) // SOURCE == POSITIVE { TP++; } else if ( ( gtImageR.at< unsigned char >( y, x ) > 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == POSITIVE ( sImageR.at < unsigned char >( y, x ) < 1 ) ) // SOURCE == NEGATIVE { FN++; } else if ( ( gtImageR.at< unsigned char >( y, x ) == 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == NEGATIVE ( sImageR.at < unsigned char >( y, x ) >= 1 ) ) // SOURCE == POSITIVE { FP++; } else if ( ( gtImageR.at< unsigned char >( y, x ) == 0 ) && ( gtImageG.at< unsigned char >( y, x ) == 0 ) && ( gtImageB.at< unsigned char >( y, x ) == 0 ) && // GROUND TRUTH == NEGATIVE ( sImageR.at < unsigned char >( y, x ) < 1 ) ) // SOURCE == NEGATIVE { TN++; } else { int gtr = gtImageR.at< unsigned char >( y, x ); int gtg = gtImageB.at< unsigned char >( y, x ); int gtb = gtImageG.at< unsigned char >( y, x ); int sr = gtImageR.at< unsigned char >( y, x ); Mojo::Core::Printf( "gtr ", gtr, ", gtg ", gtg, ", gtb ", gtb, ", sr ", sr ); RELEASE_ASSERT( 0 ); } } } } ++gtFile; ++sFile; } RELEASE_ASSERT( TP + FP + TN + FN == width * height * numImages ); Mojo::Core::Printf( "TP: ", TP ); Mojo::Core::Printf( "FP: ", FP ); Mojo::Core::Printf( "TN: ", TN ); Mojo::Core::Printf( "FN: ", FN ); } catch( std::exception e ) { Mojo::Core::Printf( "Exception: ", e.what() ); return -1; } return 0; }