本文整理汇总了C++中Dir类的典型用法代码示例。如果您正苦于以下问题:C++ Dir类的具体用法?C++ Dir怎么用?C++ Dir使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dir类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: file_size
ssize_t file_size(Dir basedir, std::string fname) {
return file_size(basedir.join(fname));
}
示例2: GetNameWithSep
//----------------------------------------------------------------------------
size_t Dir::Traverse(DirTraverser& sink, const std::string &filespec,
int flags) const
{
size_t nFiles = 0;
const std::string prefix = GetNameWithSep();
if (flags & DIR_DIRS)
{
std::string dirname;
for (bool cont = GetFirst(&dirname, "", (flags & ~(DIR_FILES | DIR_DOTDOT))|DIR_DIRS);
cont; cont = cont && GetNext(&dirname))
{
const std::string fulldirname = prefix + dirname;
switch (sink.OnDir(fulldirname))
{
default:
case DIR_STOP:
cont = false;
break;
case DIR_CONTINUE:
{
Dir subdir;
bool ok;
do
{
ok = subdir.Open(fulldirname);
if (!ok)
{
// ask the user code what to do
bool tryagain;
switch (sink.OnOpenError(fulldirname))
{
default:
PX2_LOG_ERROR("unexpected OnOpenError() return value");
// fall through
case DIR_STOP:
cont = false;
// fall through
case DIR_IGNORE:
tryagain = false;
break;
case DIR_CONTINUE:
tryagain = true;
}
if (!tryagain)
break;
}
} while (!ok);
if (ok)
{
nFiles += subdir.Traverse(sink, filespec, flags);
}
}
break;
case DIR_IGNORE:
// nothing to do
;
}
}
}
// now enum our own files
if (flags & DIR_FILES)
{
flags &= ~DIR_DIRS;
std::string filename;
bool cont = GetFirst(&filename, filespec, flags);
while (cont)
{
DirTraverseResult res = sink.OnFile(prefix + filename);
if (res == DIR_STOP)
break;
assertion(res == DIR_CONTINUE, "unexpected OnFile() return value");
nFiles++;
cont = GetNext(&filename);
}
}
return nFiles;
}
示例3: setDirectory
void ServerSideBrowserModel::setDirectory(const Dir& dir)
{
m_xmmsClient->xformMediaBrowse(dir.url())(&ServerSideBrowserModel::getDirectoryItems, this,
dir, std::placeholders::_1);
}
示例4: test_create
void test_create() {
TS_ASSERT(kind_of<Dir>(d));
TS_ASSERT(d->data()->nil_p());
}
示例5: current
//! Sets the current working directory
bool Dir::current( Dir const &dir )
{
return chdir( dir.absolute().path() ) == 0;
}
示例6:
File *Dir::getFileFromSubdir(const char *subdir, const char *file)
{
Dir *d = safecast<Dir*>(getDirByName(subdir, true, false)); // useSubtrees is irrelevant here
return d ? d->getFile(file) : NULL;
}
示例7: directoryLoadFailed
void FileSystemBrowser::directoryLoadFailed(const Dir& dir, const std::string& error)
{
StatusArea::showMessage("Can't open %s : %s", dir.name(), error);
}
示例8: sprintf
bool Collectiondb::load ( bool isDump ) {
char dname[1024];
// MDW: sprintf ( dname , "%s/collections/" , g_hostdb.m_dir );
sprintf ( dname , "%s" , g_hostdb.m_dir );
Dir d;
d.set ( dname );
if ( ! d.open ()) return log("admin: Could not load collection config "
"files.");
// note it
log(LOG_INIT,"admin: Loading collection config files.");
// . scan through all subdirs in the collections dir
// . they should be like, "coll.main/" and "coll.mycollection/"
char *f;
while ( ( f = d.getNextFilename ( "*" ) ) ) {
// skip if first char not "coll."
if ( strncmp ( f , "coll." , 5 ) != 0 ) continue;
// must end on a digit (i.e. coll.main.0)
if ( ! is_digit (f[gbstrlen(f)-1]) ) continue;
// point to collection
char *coll = f + 5;
// NULL terminate at .
char *pp = strchr ( coll , '.' );
if ( ! pp ) continue;
*pp = '\0';
// get collnum
collnum_t collnum = atol ( pp + 1 );
// add it
if ( !addRec ( coll , NULL , 0 , false , collnum , isDump ,
true ) )
return false;
}
// note it
log(LOG_INIT,"admin: Loaded data for %li collections. Ranging from "
"collection #0 to #%li.",m_numRecsUsed,m_numRecs-1);
// update the time
updateTime();
// don't clean the tree if just dumpin
if ( isDump ) return true;
// remove any nodes with illegal collnums
Rdb *r;
//r = g_indexdb.getRdb();
//r->m_tree.cleanTree ((char **)r->m_bases);
r = g_posdb.getRdb();
r->m_tree.cleanTree ((char **)r->m_bases);
//r = g_datedb.getRdb();
//r->m_tree.cleanTree ((char **)r->m_bases);
r = g_titledb.getRdb();
r->m_tree.cleanTree ((char **)r->m_bases);
//r = g_revdb.getRdb();
//r->m_tree.cleanTree ((char **)r->m_bases);
//r = g_sectiondb.getRdb();
//r->m_tree.cleanTree ((char **)r->m_bases);
//r = g_checksumdb.getRdb();
//r->m_tree.cleanTree ((char **)r->m_bases);
//r = g_tfndb.getRdb();
//r->m_tree.cleanTree ((char **)r->m_bases);
r = g_spiderdb.getRdb();
r->m_tree.cleanTree ((char **)r->m_bases);
r = g_doledb.getRdb();
r->m_tree.cleanTree ((char **)r->m_bases);
// success
return true;
}
示例9: onDirectoryLoaded
void ServerSideBrowser::onDirectoryLoaded(const Dir& dir)
{
// FIXME: Path may be too long to display
std::string path = dir.protocol() == "file" ? dir.path() : dir.url();
setName(std::string("Server side browser: ").append(path));
}
示例10: GetWin
/// \brief Mcd Draw 함수
void NCurses_Mcd::Draw()
{
WINDOW* pWin = GetWin();
vector<chtype> vLineChType;
int nRow = 0, nCol = 0, nODep=0;
int j = 0;
DrawInit();
Dir *pCur = (*_pCur);
if (pCur->nRow - _nSRow > height-3) _nSRow = pCur->nRow-height+3;
if (pCur->nDepth - _nSCol > _nRowSize) _nSCol = pCur->nDepth - _nRowSize;
if (pCur->nRow - _nSRow < 0) _nSRow = pCur->nRow;
if (pCur->nDepth - _nSCol < 1)
{
_nSCol = pCur->nDepth-1;
if (_nSCol == -1) _nSCol=0;
}
// 화면 지우기
if (!_sStrSearch.empty())
{
setcol(_tMCDColor, pWin);
mvwprintw(pWin, 0, width-25, "Search : [%-10s]", _sStrSearch.c_str());
}
setcol(_tMCDColor, pWin);
mvwprintw(pWin, height-1, 2, "Path [ %s ]", isKorCode(pCur->Path()).c_str() );
int nButtonCount = 0;
Dir *pNode = NULL;
for (pDirIterator i=_pOrder.begin(); i!=_pOrder.end(); i++)
{
pNode = *i;
if (nODep < pNode->nDepth)
vLineChType.push_back(VLINE);
else
while(pNode->nDepth < nODep)
{
nODep--;
vLineChType.pop_back();
}
nODep = pNode->nDepth;
nCol = pNode->nDepth;
nRow = pNode->nRow;
// 출력 다했으면 종료
if (pNode->nDepth != 0 && pNode->pParentDir->vNode.back()==pNode)
vLineChType[nCol-1] = ' ';
//LOG_WRITE("nODep [%d] nCol [%d] nRow [%d] _nSRow [%d] _nSCol [%d]", nODep, nCol, nRow, _nSRow, _nSCol);
//LOG_WRITE("NCurses::Draw pNode->nDepth [%d]", pNode->nDepth);
if (nRow - _nSRow > height-3) break;
if (nRow - _nSRow < 0) continue;
if (pNode != _pRoot && pNode->pParentDir->vNode.front()!= pNode)
{
for (int t = _nSCol; t < nCol && t < _nSCol+_nRowSize; t++)
{
setcol(_tMCDLine, pWin);
mvwaddch(pWin, nRow-_nSRow+1, ColLocation[t-_nSCol+1], vLineChType[t]);
}
}
if (nCol - _nSCol > _nRowSize ) continue;
if (_nSCol != 0 && nCol - _nSCol < 1 ) continue;
if (pNode->nDepth==0)
{// 루트라면
McdDirButton* pDirButton = _vDirButtonList[nButtonCount];
pDirButton->SetForm((Form*)this);
pDirButton->height = 1;
pDirButton->width = 12;
pDirButton->x = nRow-_nSRow+1;
pDirButton->y = 1;
// 선을 하나 더 긋고 이름 출력
if (pNode == pCur)
pDirButton->SetDir(pNode, _bFocus);
else
pDirButton->SetDir(pNode, false);
pDirButton->Show();
nButtonCount++;
}
else
{// 아니라면
if (pNode->pParentDir->vNode.size() > 1)
{
// 디렉토리가 하나가 아닐때
//.........这里部分代码省略.........
示例11: log
// . sets m_fileOffset and m_bf
// . returns false and sets g_errno on error
// . returns false if nothing to read too... but does not set g_errno
bool ImportState::setCurrentTitleFileAndOffset ( ) {
// leave m_bf and m_fileOffset alone if there is more to read
if ( m_fileOffset < m_bfFileSize )
return true;
CollectionRec *cr = g_collectiondb.getRec ( m_collnum );
if ( ! cr ) return false;
log("import: import finding next file");
// if ( m_offIsValid ) {
// //*off = m_fileOffset;
// return &m_bf;
// }
//m_offIsValid = true;
// look for titledb0001.dat etc. files in the
// workingDir/inject/ subdir
SafeBuf ddd;
ddd.safePrintf("%sinject",cr->m_importDir.getBufStart());
// now use the one provided. we should also provide the # of threads
if ( cr->m_importDir.getBufStart() &&
cr->m_importDir.getBufStart()[0] ) {
ddd.reset();
ddd.safeStrcpy ( cr->m_importDir.getBufStart() );
}
//
// assume we are the first filename
// set s_fileId to the minimum
//
Dir dir;
dir.set(ddd.getBufStart());
if ( ! dir.open() ) return false;
// assume none
long minFileId = -1;
// getNextFilename() writes into this
char pattern[64]; strcpy ( pattern , "titledb*" );
char *filename;
while ( ( filename = dir.getNextFilename ( pattern ) ) ) {
// filename must be a certain length
long filenameLen = gbstrlen(filename);
// we need at least "titledb0001.dat"
if ( filenameLen < 15 ) continue;
// ensure filename starts w/ our m_dbname
if ( strncmp ( filename , "titledb", 7 ) != 0 )
continue;
// skip if not .dat file
if ( ! strstr ( filename , ".dat" ) )
continue;
// then a 4 digit number should follow
char *s = filename + 7;
if ( ! isdigit(*(s+0)) ) continue;
if ( ! isdigit(*(s+1)) ) continue;
if ( ! isdigit(*(s+2)) ) continue;
if ( ! isdigit(*(s+3)) ) continue;
// convert digit to id
long id = atol(s);
// . do not accept files we've already processed
// . -1 means we haven't processed any yet
if ( m_bfFileId >= 0 && id <= m_bfFileId ) continue;
// the min of those we haven't yet processed/injected
if ( id < minFileId || minFileId < 0 ) minFileId = id;
}
// get where we left off
if ( ! m_loadedPlaceHolder ) {
// read where we left off from file if possible
char fname[256];
sprintf(fname,"%slasttitledbinjectinfo.dat",g_hostdb.m_dir);
SafeBuf ff;
ff.fillFromFile(fname);
if ( ff.length() > 1 ) {
m_loadedPlaceHolder = true;
// get the placeholder
sscanf ( ff.getBufStart()
, "%llu,%lu"
, &m_fileOffset
, &minFileId
);
}
}
// if no files! return false to indicate we are done
if ( minFileId == -1 ) return false;
// set up s_bf then
//if ( m_bfFileId != minFileId ) {
SafeBuf tmp;
tmp.safePrintf("titledb%04li-000.dat"
//,dir.getDirname()
,minFileId);
m_bf.set ( dir.getDirname() ,tmp.getBufStart() );
//.........这里部分代码省略.........
示例12: test_closed_p
void test_closed_p() {
TS_ASSERT_EQUALS(d->closed_p(state), Qtrue);
String* path = String::create(state, ".");
d->open(state, path);
TS_ASSERT_EQUALS(d->closed_p(state), Qfalse);
}
示例13: test_close
void test_close() {
String* path = String::create(state, ".");
d->open(state, path);
TS_ASSERT_EQUALS(d->close(state), Qnil);
}
示例14: test_close
void test_close() {
String* path = String::create(state, ".");
d->open(state, path);
TS_ASSERT_EQUALS(d->close(state), Qtrue);
TS_ASSERT(d->data()->nil_p());
}
示例15: test_open
void test_open() {
String* path = String::create(state, ".");
TS_ASSERT_EQUALS(d->open(state, path), Qnil);
TS_ASSERT(!d->data()->nil_p());
}