xtd 0.2.0
Loading...
Searching...
No Matches
xtd::io::directory_info Class Referencefinal
Inheritance diagram for xtd::io::directory_info:
xtd::io::file_system_info xtd::abstract_object xtd::object

Definition

Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.

Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
Definition directory_info.h:129
Provides the base class for both xtd::io::file_info and xtd::io::directory_info objects.
Definition file_system_info.h:87
#define core_export_
Define shared library export.
Definition core_export.h:13
Inheritance
xtd::io::file_system_infoxtd::io::directory_info
Header
#include <xtd/io/directory_info>
Namespace
xtd::io
Library
xtd.core
Examples
The following example demonstrates some of the main members of the xtd::io::directory_info class.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
// Specify the directories you want to manipulate.
directory_info di("c:\\MyDir");
try {
// Determine whether the directory exists.
if (di.exists()) {
// Indicate that the directory already exists.
console::write_line("That path exists already.");
return;
}
// Try to create the directory.
di.create();
console::write_line("The directory was created successfully.");
// Delete the directory.
di.remove();
console::write_line("The directory was deleted successfully.");
}
catch (const system_exception& e) {
console::write_line("The process failed: {0}", e.to_string());
}
}
};
startup_(program::main);
Defines the base class for predefined exceptions in the xtd namespace.
Definition system_exception.h:24
#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
@ e
The E key.
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
Examples
The following example demonstrates how to copy a directory and its contents.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::io;
class copy_dir {
public:
static void copy_all(const directory_info& source, const directory_info& target) {
if (source.full_name().to_lower() == target.full_name().to_lower()) {
return;
}
// Check if the target directory exists, if not, create it.
if (directory::exists(target.full_name()) == false) {
directory::create_directory(target.full_name());
}
// Copy each file into it's new directory.
for (file_info fi : source.get_files()) {
console::write_line("Copying {0}\\{1}", target.full_name(), fi.name());
fi.copy_to(path::combine(target.to_string(), fi.name()), true);
}
// Copy each subdirectory using recursion.
for (directory_info di_source_sub_dir : source.get_directories()) {
directory_info next_target_sub_dir = target.create_subdirectory(di_source_sub_dir.name());
copy_all(di_source_sub_dir, next_target_sub_dir);
}
}
static auto main() {
string source_directory = "c:\\source_directory";
string target_directory = "c:\\target_directory";
directory_info di_source(source_directory);
directory_info di_target(target_directory);
copy_all(di_source, di_target);
}
};
startup_(copy_dir::main);
// Output will vary based on the contents of the source directory.
basic_string to_lower() const noexcept
Returns a copy of the current xtd::basic_string converted to lowercase.
Definition basic_string.h:1809
xtd::io::directory_info create_subdirectory(const xtd::string &path) const
Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to...
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file_info.h:41
xtd::string full_name() const
Gets the full path of the directory or file.
xtd::string to_string() const noexcept override
Returns the original path. Use the xtd::io::file_system_info::full_name or xtd::io::file_system_info:...
Remarks
Use the xtd::io::directory_info class for typical operations such as copying, moving, renaming, creating, and deleting directories.
If you are going to reuse an object several times, consider using the instance method of xtd::io::directory_info instead of the corresponding static methods of the xtd::io::directory class, because a security check will not always be necessary.
Note
In members that accept a path as an input string, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space, the path is not trimmed in methods of the class. Therefore, the path is malformed and an exception is raised. Similarly, a path or a combination of paths cannot be fully qualified twice. For example, "c:\temp c:\windows" also raises an exception in most cases. Ensure that your paths are well-formed when using methods that accept a path string.
Remarks
In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:
  • "c:\\MyDir\\MyFile.txt".
  • "c:\\MyDir".
  • "MyDir\\MySubdir".
  • "\\\\MyServer\\MyShare".
By default, full read/write access to new directories is granted to all users.
For a list of common I/O tasks, see Common I/O Tasks.
Examples
directory_assert.cpp, directory_assert_are_equal.cpp, directory_assert_are_not_equal.cpp, directory_assert_does_not_exist.cpp, directory_assert_exists.cpp, directory_assume.cpp, directory_assume_are_equal.cpp, directory_assume_are_not_equal.cpp, directory_assume_does_not_exist.cpp, directory_assume_exists.cpp, directory_info.cpp, directory_valid.cpp, directory_valid_are_equal.cpp, directory_valid_are_not_equal.cpp, directory_valid_does_not_exist.cpp, directory_valid_exists.cpp, and file_info_move_to.cpp.

Classes

class  directory_iterator
 Represent directory iterator used by xtd::io::directory_info. More...
 
class  file_iterator
 Represent file iterator used by xtd::io::directory_info. More...
 
class  file_system_info_iterator
 Represent file system iterator used by xtd::io::directory_info. More...
 

Public Fields

static const directory_info empty
 Represents the uninitialized xtd::io::directory_info object. This field is constant.
 

Public Constructors

 directory_info (const xtd::string &path)
 Initializes a new instance of the xtd::io::directory_info class on the specified path.
 

Properrties

bool exists () const override
 Gets a value indicating whether the directory exists.
 
xtd::string name () const override
 Gets the name of this xtd::io::directory_info instance.
 
xtd::io::directory_info parent () const
 Gets the parent directory of a specified subdirectory.
 
xtd::io::directory_info root () const
 Gets the root portion of the directory.
 

Public Methods

void create ()
 Creates a directory.
 
xtd::io::directory_info create_subdirectory (const xtd::string &path) const
 Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the xtd::io::directory_info class.
 
xtd::io::directory_info::directory_iterator enumerate_directories () const
 Returns an enumerable collection of directory information in the current directory.
 
xtd::io::directory_info::directory_iterator enumerate_directories (const xtd::string &search_pattern) const
 Returns an enumerable collection of directory information that matches a specified search pattern.
 
xtd::io::directory_info::file_iterator enumerate_files () const
 Returns an enumerable collection of file information in the current directory.
 
xtd::io::directory_info::file_iterator enumerate_files (const xtd::string &search_pattern) const
 Returns an enumerable collection of file information that matches a search pattern.
 
xtd::io::directory_info::file_system_info_iterator enumerate_file_system_infos () const
 Returns an enumerable collection of file system information in the current directory.
 
xtd::io::directory_info::file_system_info_iterator enumerate_file_system_infos (const xtd::string &search_pattern) const
 Returns an enumerable collection of file system information that matches a specified search pattern.
 
std::vector< xtd::io::directory_infoget_directories () const
 Returns the subdirectories of the current directory.
 
std::vector< xtd::io::directory_infoget_directories (const xtd::string &search_pattern) const
 Returns an array of directories in the current DirectoryInfo matching the given search criteria.
 
std::vector< xtd::io::file_infoget_files () const
 Returns a file list from the current directory.
 
std::vector< xtd::io::file_infoget_files (const xtd::string &search_pattern) const
 Returns a file list from the current directory matching the given search pattern.
 
std::vector< xtd::sptr< xtd::io::file_system_info > > get_file_system_infos () const
 Returns an array of strongly typed xtd::io::file_system_info entries representing all the files and subdirectories in a directory.
 
std::vector< xtd::sptr< xtd::io::file_system_info > > get_file_system_infos (const xtd::string &search_pattern) const
 Retrieves an array of strongly typed FileSystemInfo objects representing the files and subdirectories that match the specified search criteria.
 
void move_to (const xtd::string &dest_dir_name)
 Moves a DirectoryInfo instance and its contents to a new path.
 
void remove () const override
 Deletes this xtd::io::directory_info if it is empty.
 
void remove (bool recursive) const
 Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::io::file_system_info
xtd::io::file_attributes attributes () const
 Gets the attributes for the current file or directory.
 
xtd::io::file_system_infoattributes (xtd::io::file_attributes value)
 Sets the attributes for the current file or directory.
 
const xtd::date_timecreation_time () const
 Gets the creation time of the current file or directory.
 
xtd::io::file_system_infocreation_time (const xtd::date_time &value)
 Gets the creation time of the current file or directory.
 
xtd::date_time creation_time_utc () const
 Gets the creation time, in coordinated universal time (UTC), of the current file or directory.
 
xtd::io::file_system_infocreation_time_utc (const xtd::date_time &value)
 Sets the creation time, in coordinated universal time (UTC), of the current file or directory.
 
virtual xtd::string extension () const
 Gets the extension part of the file name, including the leading dot . even if it is the entire file name, or an empty string if no extension is present.
 
xtd::string full_name () const
 Gets the full path of the directory or file.
 
const xtd::date_timelast_access_time () const
 Gets the time the current file or directory was last accessed.
 
xtd::io::file_system_infolast_access_time (const xtd::date_time &value)
 Sets the time the current file or directory was last accessed.
 
xtd::date_time last_access_time_utc () const
 Gets the time, in coordinated universal time (UTC), that the current file or directory was last accessed.
 
xtd::io::file_system_infolast_access_time_utc (const xtd::date_time &value)
 Sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed.
 
const xtd::date_timelast_write_time () const
 Gets the time when the current file or directory was last written to.
 
xtd::io::file_system_infolast_write_time (const xtd::date_time &value)
 Sets the time when the current file or directory was last written to.
 
xtd::date_time last_write_time_utc () const
 Gets the time, in coordinated universal time (UTC), when the current file or directory was last written to.
 
xtd::io::file_system_infolast_write_time_utc (const xtd::date_time &value)
 Sets the time, in coordinated universal time (UTC), when the current file or directory was last written to.
 
xtd::io::file_permissions permissions () const
 Gets the permissions for the current file or directory.
 
xtd::io::file_system_infopermissions (xtd::io::file_permissions value)
 Sets the permissions for the current file or directory.
 
void refresh ()
 Refreshes the state of the object.
 
xtd::string to_string () const noexcept override
 Returns the original path. Use the xtd::io::file_system_info::full_name or xtd::io::file_system_info::name properties for the full path or file/directory name.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
- Protected Attributes inherited from xtd::io::file_system_info
xtd::string full_path_
 Represents the fully qualified path of the directory or file.
 
xtd::string original_path_
 The path originally specified by the user, whether relative or absolute.
 
- Protected Member Functions inherited from xtd::io::file_system_info
 file_system_info ()=default
 Initializes a new instance of the xtd::io::file_system_info class.
 
- Protected Member Functions inherited from xtd::abstract_object
 abstract_object ()=default
 Initializes a new instance of the xtd::abstract_object class.
 

The documentation for this class was generated from the following file: