xtd 0.2.0
Loading...
Searching...
No Matches

◆ exists()

bool xtd::io::directory_info::exists ( ) const
overridevirtual

Gets a value indicating whether the directory exists.

Returns
true if the directory exists; otherwise, false.
Examples
The following example demonstrates a use of the Exists property in the context of copying a source directory to a target directory.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::io;
class program {
public:
// Copy a source directory to a target directory.
static void copy_directory(const string& source_directory, const string& target_directory) {
directory_info source(source_directory);
directory_info target(target_directory);
//Determine whether the source directory exists.
if(!source.exists())
return;
if(!target.exists())
target.create();
//Copy files.
list<file_info> source_files = source.get_files();
for(size_t i = 0; i < source_files.size(); ++i)
file::copy(source_files[i].full_name(), target.full_name() +"\\" + source_files[i].name(), true);
//Copy directories.
list<directory_info> source_directories = source.get_directories();
for(size_t j = 0; j < source_directories.size(); ++j)
copy_directory(source_directories[j].full_name(), target.full_name() + "\\" + source_directories[j].name());
}
static auto main() {
// Specify the directories you want to manipulate.
copy_directory("D:\\Tools","D:\\NewTools");
}
};
startup_(program::main);
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::collections::generic::list::...
Definition list.h:365
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:72
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
Definition directory_info.h:129
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
@ j
The J key.
@ i
The I key.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.h:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Remarks
The xtd::io::directory_info::exists property returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.

Implements xtd::io::file_system_info.