本文整理汇总了C++中Directory::DirectoryExists方法的典型用法代码示例。如果您正苦于以下问题:C++ Directory::DirectoryExists方法的具体用法?C++ Directory::DirectoryExists怎么用?C++ Directory::DirectoryExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Directory
的用法示例。
在下文中一共展示了Directory::DirectoryExists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeDirectory
void xmlRep::makeDirectory(std::string Key,xmlRep rape)
{
Directory dir;
if(dir.DirectoryExists(TEXT("test")))
{
dir.SetCurrentDirectory(TEXT("./test"));
ofstream myfile;
myfile.open (Key+".xml");
myfile << rape.format();
myfile.close();
dir.SetCurrentDirectory(TEXT("../"));
}
else
{
dir.CreateDirectory(TEXT("test"));
dir.SetCurrentDirectory(TEXT("./test"));
ofstream myfile;
myfile.open (Key+".xml");
myfile << rape.format();
myfile.close();
dir.SetCurrentDirectory(TEXT("../"));
}
}
示例2: main
int main() {
stdOut << "\n Testing WinTools ";
stdOut << "\n ==================\n";
SystemError se;
stdOut << TEXT("\n Last error code = ") << ::GetLastError();
stdOut << TEXT("\n Last error message = ") << se.GetLastMsg();
stdOut << std::endl;
std::cout << "\n testing directory management ";
std::cout << "\n ------------------------------";
Directory dir;
if(dir.DirectoryExists(TEXT("test")))
{
std::cout << "\n Directory test exists";
if(dir.RemoveDirectory(TEXT("test")))
std::cout << "\n successfully removed directory test";
}
else
{
if(dir.CreateDirectory(TEXT("test")))
std::cout << "\n successfully created directory test";
else
std::cout << "\n Directory creation failed";
}
stdOut << TEXT("\n Current directory is: ") << dir.GetCurrentDirectory();
if(dir.SetCurrentDirectory(TEXT("./test")))
{
stdOut << TEXT("\n changed to: ") << dir.GetCurrentDirectory();
dir.SetCurrentDirectory(TEXT(".."));
stdOut << TEXT("\n changed back to: ") << dir.GetCurrentDirectory();
}
std::cout << std::endl;
std::vector<stdStr> files = Directory::GetFiles();
std::cout << "\n files in this directory are:";
for(size_t i=0; i<files.size(); ++i)
stdOut << TEXT("\n ") << files[i];
std::cout << std::endl;
files = Directory::GetFiles(TEXT("*.h*"));
std::cout << "\n *.h* files in this directory are:";
for(size_t i=0; i<files.size(); ++i)
stdOut << TEXT("\n ") << files[i];
std::cout << std::endl;
std::vector<stdStr> dirs = Directory::GetDirectories();
std::cout << "\n directories in this directory are:";
for(size_t i=0; i<dirs.size(); ++i)
stdOut << TEXT("\n ") << dirs[i];
std::cout << std::endl;
std::cout << "\n testing Path management ";
std::cout << "\n -------------------------";
stdStr paths[] = { TEXT("aFile"), TEXT("../../aFile"), TEXT("test/aFile"), TEXT("../../") };
for(int i=0; i<4; ++i)
{
stdOut << TEXT("\n fileSpec: ") << std::setw(12) << paths[i];
stdOut << TEXT(", name: ") << Path::getName(paths[i]);
stdOut << TEXT("\n fileSpec: ") << std::setw(12) << paths[i];
stdOut << TEXT(", path: ") << Path::getPath(paths[i]);
}
std::cout << std::endl;
std::cout << "\n testing error messages ";
std::cout << "\n ------------------------";
int err = GetLastError();
std::cout << "\n Last error code = " << err;
try {
se.ThrowString(TEXT("throw message"),Convert::ToStdStr(__FILE__),__LINE__);
}
catch(const stdStr &msg)
{
stdOut << TEXT("\n ") << msg;
}
std::cout << "\n";
std::cout << "\n test writing to \"Program Files\" Folder ";
std::cout << "\n ------------------------------------------";
stdStr CurrDir = Path::getFullPath(TEXT("."));
stdStr fileSpec = CurrDir + TEXT("*.*");
if(Directory::SetCurrentDirectory(TEXT("C:/Program Files")))
{
std::cout << "\n sucessfully set directory to \"C:\\Program Files\"";
if(Directory::DirectoryExists(TEXT("foobar stuff")))
{
std::cout << "\n \"C:\\Program Files\\foobar stuff\" exists";
if(!Directory::CopyFiles(fileSpec,TEXT("C:\\Program Files\\foobar stuff")))
std::cout << "\n one or more file copy operations failed";
else
std::cout << "\n all file copy operations succeeded";
}
else if(Directory::CreateDirectory(TEXT("foobar stuff")))
//.........这里部分代码省略.........