本文整理汇总了C++中IsDirectory函数的典型用法代码示例。如果您正苦于以下问题:C++ IsDirectory函数的具体用法?C++ IsDirectory怎么用?C++ IsDirectory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsDirectory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetSize
// Returns the size of filename (64bit)
u64 GetSize(const std::string &filename)
{
struct stat64 file_info;
#if defined(_WIN32) && defined(UNICODE)
int result = _wstat64(ConvertUTF8ToWString(filename).c_str(), &file_info);
#else
int result = stat64(filename.c_str(), &file_info);
#endif
if (result != 0)
{
WARN_LOG(COMMON, "GetSize: failed %s: No such file", filename.c_str());
return 0;
}
if (IsDirectory(file_info))
{
WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str());
return 0;
}
DEBUG_LOG(COMMON, "GetSize: %s: %lld", filename.c_str(), (long long)file_info.st_size);
return file_info.st_size;
}
示例2: CtdlDirectoryLookup
/*
* Look up an Internet e-mail address in the directory.
* On success: returns 0, and Citadel address stored in 'target'
* On failure: returns nonzero
*/
int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) {
struct cdbdata *cdbrec;
char key[SIZ];
/* Dump it in there unchanged, just for kicks */
safestrncpy(target, internet_addr, targbuflen);
/* Only do lookups for addresses with hostnames in them */
if (num_tokens(internet_addr, '@') != 2) return(-1);
/* Only do lookups for domains in the directory */
if (IsDirectory(internet_addr, 0) == 0) return(-1);
directory_key(key, internet_addr);
cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) );
if (cdbrec != NULL) {
safestrncpy(target, cdbrec->ptr, targbuflen);
cdb_free(cdbrec);
return(0);
}
return(-1);
}
示例3: CopyDir
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string &source_path, const std::string &dest_path)
{
#ifndef _WIN32
if (source_path == dest_path) return;
if (!File::Exists(source_path)) return;
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
struct dirent_large { struct dirent entry; char padding[FILENAME_MAX+1]; };
struct dirent_large diren;
struct dirent *result = NULL;
DIR *dirp = opendir(source_path.c_str());
if (!dirp) return;
while (!readdir_r(dirp, (dirent*) &diren, &result) && result)
{
const std::string virtualName(result->d_name);
// check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0')))
continue;
std::string source, dest;
source = source_path + virtualName;
dest = dest_path + virtualName;
if (IsDirectory(source))
{
source += '/';
dest += '/';
if (!File::Exists(dest)) File::CreateFullPath(dest);
CopyDir(source, dest);
}
else if (!File::Exists(dest)) File::Copy(source, dest);
}
closedir(dirp);
#endif
}
示例4: CopyDir
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string &source_path, const std::string &dest_path)
{
#ifndef _WIN32
if (source_path == dest_path) return;
if (!File::Exists(source_path)) return;
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
struct dirent *result = NULL;
DIR *dirp = opendir(source_path.c_str());
if (!dirp) return;
while ((result = readdir(dirp)))
{
const std::string virtualName(result->d_name);
// check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0')))
continue;
std::string source, dest;
source = source_path + virtualName;
dest = dest_path + virtualName;
if (IsDirectory(source))
{
source += '/';
dest += '/';
if (!File::Exists(dest)) File::CreateFullPath(dest);
CopyDir(source, dest);
}
else if (!File::Exists(dest)) File::Copy(source, dest);
}
closedir(dirp);
#else
ERROR_LOG(COMMON, "CopyDir not supported on this platform");
#endif
}
示例5: opendir
void UserTable::GetDirectoryTree(const std::string& sPath, TPathList& rResults)
{
struct dirent* ent;
DIR* dir;
dir = opendir(sPath.c_str());
if (!dir) {
syslog(LOG_WARNING, "could not open directory %s: %s", sPath.c_str(), strerror(errno));
return;
}
rResults.push_back(sPath);
ent = readdir(dir);
while (ent) {
std::string sFullPath = sPath + "/" + ent->d_name;
std::string sEntry(ent->d_name);
if ("." != sEntry && ".." != sEntry && IsDirectory(sFullPath)) {
GetDirectoryTree(sFullPath, rResults);
}
ent = readdir(dir);
}
closedir(dir);
}
示例6: set
/*
Removes a single directory passed in.
Returns true on success, false on failure.
On a failure, errno will be set (but may be of dubious quality)
and an error logged.
If the path does not exist, return immediately as success.
if the path exists, but is not a directory, the behavior is currently
to return immediately as success, but in the future might fail with
errno==ENOTDIR.
This assumes that the top level directory requires an euid of condor to
remove.
*/
static bool
remove_spool_directory(const char * dir)
{
if ( ! IsDirectory(dir) ) { return true; }
Directory spool_dir(dir);
if( ! spool_dir.Remove_Entire_Directory() )
{
dprintf(D_ALWAYS,"Failed to remove %s\n", dir);
errno = EPERM; // Wild guess.
return false;
}
TemporaryPrivSentry tps(PRIV_CONDOR);
if( rmdir(dir) == 0 ) { return true; }
// Save errno in case dprintf mangles.
int tmp_errno = errno;
if( errno != ENOENT ) {
dprintf(D_ALWAYS,"Failed to remove %s: %s (errno %d)\n",
dir, strerror(errno), errno );
}
errno = tmp_errno;
return false;
}
示例7: ValidatePath
/*---------------------------------------------------------------------*/
BOOL ValidatePath(CHAR * path, H_ARCHIVE harchive)
{
_archive[harchive].last_error = ARC_NO_ERROR;
_archive_error = ARC_NO_ERROR;
/* Check out the path */
if (path == NULL)
_archive_error = ARC_BAD_PATH;
if (strlen(path) > MAX_PATH_LEN - ARC_PATH_LEN)
_archive_error = ARC_BAD_PATH;
if (!IsDirectory(path))
_archive_error = ARC_BAD_PATH;
if (_archive_error != ARC_NO_ERROR)
return (FALSE);
/* Fully qualify the path */
QualifyPath(_archive[harchive].path, path);
return (TRUE);
}
示例8: EnsureBackslashPathSet
bool CTGitPath::Delete(bool bTrash) const
{
EnsureBackslashPathSet();
::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
bool bRet = false;
if (Exists())
{
if ((bTrash)||(IsDirectory()))
{
std::unique_ptr<TCHAR[]> buf(new TCHAR[m_sBackslashPath.GetLength() + 2]);
_tcscpy_s(buf.get(), m_sBackslashPath.GetLength() + 2, m_sBackslashPath);
buf[m_sBackslashPath.GetLength()] = 0;
buf[m_sBackslashPath.GetLength()+1] = 0;
bRet = CTGitPathList::DeleteViaShell(buf.get(), bTrash);
}
else
{
bRet = !!::DeleteFile(m_sBackslashPath);
}
}
m_bExists = false;
m_bExistsKnown = true;
return bRet;
}
示例9: CreateFullPath
// Creates the full path of fullPath returns true on success
bool CreateFullPath(const std::string& fullPath)
{
int panicCounter = 100;
INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str());
if (Exists(fullPath))
{
INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath.c_str());
return true;
}
size_t position = 0;
while (true)
{
// Find next sub path
position = fullPath.find(DIR_SEP_CHR, position);
// we're done, yay!
if (position == fullPath.npos)
return true;
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
std::string const subPath(fullPath.substr(0, position + 1));
if (!IsDirectory(subPath))
File::CreateDir(subPath);
// A safety check
panicCounter--;
if (panicCounter <= 0)
{
ERROR_LOG(COMMON, "CreateFullPath: directory structure is too deep");
return false;
}
position++;
}
}
示例10: Delete
// Deletes a given filename, return true on success
// Doesn't supports deleting a directory
bool Delete(const std::string &filename)
{
INFO_LOG(COMMON, "Delete: file %s", filename.c_str());
// Return true because we care about the file no
// being there, not the actual delete.
if (!Exists(filename))
{
WARN_LOG(COMMON, "Delete: %s does not exists", filename.c_str());
return true;
}
// We can't delete a directory
if (IsDirectory(filename))
{
WARN_LOG(COMMON, "Delete failed: %s is a directory", filename.c_str());
return false;
}
#ifdef _WIN32
if (!DeleteFile(ConvertUTF8ToWString(filename).c_str()))
{
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
filename.c_str(), GetLastErrorMsg());
return false;
}
#else
if (unlink(filename.c_str()) == -1) {
WARN_LOG(COMMON, "Delete: unlink failed on %s: %s",
filename.c_str(), GetLastErrorMsg());
return false;
}
#endif
return true;
}
示例11: MoveToDir
//----------------------------------------------------------------------------------------
nsresult nsFileSpec::MoveToDir(const nsFileSpec& inNewParentDirectory)
//----------------------------------------------------------------------------------------
{
// We can only copy into a directory, and (for now) can not copy entire directories
if (inNewParentDirectory.IsDirectory() && (! IsDirectory() ) )
{
char *leafname = GetLeafName();
nsSimpleCharString destPath(inNewParentDirectory.GetCString());
destPath += "\\";
destPath += leafname;
nsCRT::free(leafname);
// MoveFile returns non-zero if succeeds
int copyOK = MoveFile(GetCString(), destPath);
if (copyOK)
{
*this = inNewParentDirectory + GetLeafName();
return NS_OK;
}
}
return NS_FILE_FAILURE;
} // nsFileSpec::MoveToDir
示例12: InitHomeDir
void InitHomeDir(void)
{
const std::string & home = Settings::GetHomeDir();
if(! home.empty())
{
const std::string home_maps = home + SEPARATOR + std::string("maps");
const std::string home_files = home + SEPARATOR + std::string("files");
const std::string home_files_save = home_files + SEPARATOR + std::string("save");
if(! IsDirectory(home))
MKDIR(home.c_str());
if(IsDirectory(home, true) && ! IsDirectory(home_maps))
MKDIR(home_maps.c_str());
if(IsDirectory(home, true) && ! IsDirectory(home_files))
MKDIR(home_files.c_str());
if(IsDirectory(home_files, true) && ! IsDirectory(home_files_save))
MKDIR(home_files_save.c_str());
}
}
示例13: ScanDirectoryTree
// Scans the directory tree gets, starting from _Directory and adds the
// results into parentEntry. Returns the number of files+directories found
u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
{
INFO_LOG(COMMON, "ScanDirectoryTree: directory %s", directory.c_str());
// How many files + directories we found
u32 foundEntries = 0;
#ifdef _WIN32
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(UTF8ToTStr(directory + "\\*").c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return foundEntries;
}
// windows loop
do
{
FSTEntry entry;
const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
struct dirent dirent, *result = NULL;
DIR *dirp = opendir(directory.c_str());
if (!dirp)
return 0;
// non windows loop
while (!readdir_r(dirp, &dirent, &result) && result)
{
FSTEntry entry;
const std::string virtualName(result->d_name);
#endif
// check for "." and ".."
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
(virtualName[2] == '\0')))
continue;
entry.virtualName = virtualName;
entry.physicalName = directory;
entry.physicalName += DIR_SEP + entry.virtualName;
if (IsDirectory(entry.physicalName.c_str()))
{
entry.isDirectory = true;
// is a directory, lets go inside
entry.size = ScanDirectoryTree(entry.physicalName, entry);
foundEntries += (u32)entry.size;
}
else
{ // is a file
entry.isDirectory = false;
entry.size = GetSize(entry.physicalName.c_str());
}
++foundEntries;
// Push into the tree
parentEntry.children.push_back(entry);
#ifdef _WIN32
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
#else
}
closedir(dirp);
#endif
// Return number of entries found.
return foundEntries;
}
示例14: EditFile
/*
* EditFile - read a file into text
*/
vi_rc EditFile( char *name, bool dammit )
{
char *fn, **list, *currfn;
int i, cnt, ocnt;
int j, len;
window_id wn = NO_WINDOW;
char cdir[FILENAME_MAX];
info *ci, *il;
bool usedir = false;
char mask[FILENAME_MAX];
bool reset_dir;
int index;
char *altname = NULL;
vi_rc rc;
fn = MemAlloc( FILENAME_MAX );
/*
* get file name
*/
strcpy( cdir, CurrentDirectory );
reset_dir = false;
RemoveLeadingSpaces( name );
if( name[0] == '$' ) {
EliminateFirstN( name, 1 );
usedir = true;
}
fn[0] = 0;
// if( NextWord1( name, fn ) <= 0 )
if( GetStringWithPossibleQuote2( name, fn, false ) != ERR_NO_ERR ) {
usedir = true;
mask[0] = '*';
mask[1] = 0;
}
if( usedir ) {
if( EditFlags.ExMode ) {
MemFree( fn );
return( ERR_INVALID_IN_EX_MODE );
}
len = strlen( fn );
if( len > 0 ) {
i = len - 1;
strcpy( mask, fn );
cnt = 0;
while( i >= 0 ) {
if( fn[i] == FILE_SEP ) {
for( j = i + 1; j <= len; j++ ) {
mask[j - (i + 1)] = fn[j];
}
cnt = i;
break;
}
i--;
}
fn[cnt] = 0;
}
if( fn[0] != 0 ) {
rc = SelectFileOpen( fn, &fn, mask, true );
} else {
#ifdef __WIN__
if( name[0] == '\0' ) {
altname = MemAlloc( 1000 );
rc = SelectFileOpen( CurrentDirectory, &altname, mask, true );
NextWord1( altname, fn ); // if multiple, kill path
if( isMultipleFiles( altname ) ) {
NextWord1( altname, fn ); // get 1st name
}
} else {
rc = SelectFileOpen( CurrentDirectory, &fn, mask, true );
}
#else
rc = SelectFileOpen( CurrentDirectory, &fn, mask, true );
#endif
}
if( altname ) {
name = altname;
}
if( rc != ERR_NO_ERR || fn[0] == 0 ) {
MemFree( fn );
SetCWD( cdir );
return( rc );
}
}
/*
* loop through all files
*/
rc = ERR_NO_ERR;
EditFlags.WatchForBreak = true;
#ifdef __WIN__
ToggleHourglass( true );
#endif
do {
if( IsDirectory( fn ) ) {
if( EditFlags.ExMode ) {
rc = ERR_INVALID_IN_EX_MODE;
//.........这里部分代码省略.........
示例15: TEST_NFILEUTILITIES
};
//============================================================================
// Test case
//----------------------------------------------------------------------------
TEST_NFILEUTILITIES("Directories")
{
// Perform the test
theFile = NFileUtilities::GetDirectory(kNLocationHome);
REQUIRE(theFile.IsDirectory());
theFile = NFileUtilities::GetDirectory(kNLocationDesktop);
REQUIRE(theFile.IsDirectory());
theFile = NFileUtilities::GetDirectory(kNLocationPreferences);
REQUIRE(theFile.IsDirectory());
theFile = NFileUtilities::GetCWD();
REQUIRE(theFile.IsDirectory());
}