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

◆ length()

size_t xtd::io::file_info::length ( ) const

Gets the size, in bytes, of the current file.

Returns
The size of the current file in bytes.
Exceptions
xtd::io::io_exceptionxtd::io::file_info::refresh cannot update the state of the file or directory.
xtd::io::file_not_found_exceptionThe file does not exist.
-or-
The xtd::io::file_info::size property is called for a directory.
Examples
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::io;
auto main() -> int {
// Make a reference to a directory.
directory_info di("c:\\");
// Get a reference to each file in that directory.
lidt<file_info> fi_arr = di.get_files();
// Display the names and sizes of the files.
console::write_line("The directory {0} contains the following files:", di.name());
for (file_info f : fi_arr)
console::write_line("The size of {0} is {1} bytes.", f.name(), f.length());
}
// This code produces the following to the following;
// results may vary based on the computer/file structure/etc.:
//
// The directory c:\ contains the following files:
// The size of MyComputer.log is 274 bytes.
// The size of AUTOEXEC.BAT is 0 bytes.
// The size of boot.ini is 211 bytes.
// The size of CONFIG.SYS is 0 bytes.
// The size of hiberfil.sys is 1072775168 bytes.
// The size of IO.SYS is 0 bytes.
// The size of MASK.txt is 2700 bytes.
// The size of mfc80.dll is 1093632 bytes.
// The size of mfc80u.dll is 1079808 bytes.
// The size of MSDOS.SYS is 0 bytes.
// The size of NTDETECT.COM is 47564 bytes.
// The size of ntldr is 250032 bytes.
// The size of pagefile.sys is 1610612736 bytes.
// The size of UpdatePatch.log is 22778 bytes.
// The size of UpdatePatch.txt is 30 bytes.
// The size of wt3d.ini is 234 bytes.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Represents the standard input, output, and error streams for console applications.
Definition console.h:36
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
Definition directory_info.h:129
size_t length() const
Gets the size, in bytes, of the current file.
xtd::string name() const override
Gets the name of the file.
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file_info.h:41
@ f
The F 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 value of the Length property is pre-cached if the current instance of the xtd::io::file_info object was returned from any of the following DirectoryInfo methods:
  • xtd::io::file_info::get_directories
  • xtd::io::file_info::_det_files
  • xtd::io::file_info::get_file_system_infos
  • xtd::io::file_info::enumerate_directories
  • xtd::io::file_info::enumerate_files
  • xtd::io::file_info::enumerate_file_system_infos
  • To get the latest value, call the xtd::io::file_info::refresh method.
Examples
file_info2.cpp.