Provides methods for manipulating files. More...

Static Public Member Functions

static void AppendAllLines (const String &path, const SharedPtr< Collections::Generic::IEnumerable< String >> &contents, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static void AppendAllText (const String &path, const String &contents, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static StreamWriterPtr AppendText (const String &path)
 
static void Copy (const String &sourceFileName, const String &destFileName, bool overwrite=false)
 
static FileStreamPtr Create (const String &path, int bufferSize=DefaultBufferSize, FileOptions options=FileOptions::None)
 
static StreamWriterPtr CreateText (const String &path)
 
static void Decrypt (const String &path)
 
static void Delete (const String &path)
 
static void Encrypt (const String &path)
 
static bool Exists (const String &path)
 
static FileAttributes GetAttributes (const String &path)
 
static DateTime GetCreationTime (const String &path)
 
static DateTime GetCreationTimeUtc (const String &path)
 
static DateTime GetLastAccessTime (const String &path)
 
static DateTime GetLastAccessTimeUtc (const String &path)
 
static DateTime GetLastWriteTime (const String &path)
 
static DateTime GetLastWriteTimeUtc (const String &path)
 
static void Move (const String &sourceFileName, const String &destFileName)
 
static FileStreamPtr Open (const String &path, FileMode mode)
 
static FileStreamPtr Open (const String &path, FileMode mode, FileAccess access, FileShare share=FileShare::None)
 
static FileStreamPtr OpenRead (const String &path)
 
static StreamReaderPtr OpenText (const String &path, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static FileStreamPtr OpenWrite (const String &path)
 
static ArrayPtr< uint8_t > ReadAllBytes (const String &path)
 
static ArrayPtr< StringReadAllLines (const String &path, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static String ReadAllText (const String &path, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static SharedPtr< Collections::Generic::IEnumerable< String > > ReadLines (const String &path, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static void Replace (const String &sourceFileName, const String &destinationFileName, const String &destinationBackupFileName, bool ignoreMetadataErrors=true)
 TODO. More...
 
static void SetAttributes (const String &path, FileAttributes fileAttributes)
 
static void SetCreationTime (const String &path, DateTime creationTime)
 
static void SetCreationTimeUtc (const String &path, DateTime creationTimeUtc)
 
static void SetLastWriteTime (const String &path, DateTime lastWriteTime)
 
static void SetLastWriteTimeUtc (const String &path, DateTime lastWriteTimeUtc)
 
static void SetLastAccessTime (const String &path, DateTime lastWriteTime)
 
static void SetLastAccessTimeUtc (const String &path, DateTime lastWriteTimeUtc)
 
static void WriteAllBytes (const String &path, const ArrayPtr< uint8_t > &bytes)
 
static void WriteAllLines (const String &path, const SharedPtr< Collections::Generic::IEnumerable< String >> &contents, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static void WriteAllLines (const String &path, const ArrayPtr< String > &contents, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 
static void WriteAllText (const String &path, const String &contents, const EncodingPtr &encoding=Text::Encoding::get_UTF8Unmarked())
 

Static Public Attributes

static const int ASPOSECPP_SHARED_API DefaultBufferSize
 Default value of the number of bytes bufferred during reading from and writing to a file. More...
 

Detailed Description

Provides methods for manipulating files.

Member Function Documentation

◆ AppendAllLines()

static void System::IO::File::AppendAllLines ( const String path,
const SharedPtr< Collections::Generic::IEnumerable< String >> &  contents,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Appends strings from the specified collection of strings to the specified file using the specified encoding by writing each string in a new line. If the specified file does not exist, it is created. The file is closed after writing all strings.

Parameters
pathThe path of the file to append the strings to
contentsThe strings to write to the file
encodingThe character encoding to use

◆ AppendAllText()

static void System::IO::File::AppendAllText ( const String path,
const String contents,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Appends the specified string to the specified file using the specified encoding.

Parameters
pathThe path of the file to append the string to
contentsThe string to write to the file
encodingThe character encoding to use

◆ AppendText()

static StreamWriterPtr System::IO::File::AppendText ( const String path)
static

Creates a StreamWriter object that appends text to the specified file using UTF-8 encoding. If the specified file does not exist, it is created.

Parameters
pathThe path of the file to open or create
Returns
A shared pointer to the created StreamWriter object associated with the specified file

◆ Copy()

static void System::IO::File::Copy ( const String sourceFileName,
const String destFileName,
bool  overwrite = false 
)
static

Copies the specified file to the specified location. If the destination file already exists, a paremeter specifies if it should be overwritten.

Parameters
sourceFileNameA path of the file to copy
destFileNameA path of the new location of the file to copy
Returns
A FileInfo object that represents the copy
Parameters
overwriteTrue if the existing destination file should be overwritten, false if copying should fail if the destination file already exists

◆ Create()

static FileStreamPtr System::IO::File::Create ( const String path,
int  bufferSize = DefaultBufferSize,
FileOptions  options = FileOptions::None 
)
static

Creates a new file (or overwrites existing) and opens it for reading and writing access using the specified buffer size and options.

Parameters
pathThe path of the file to create or overwrite
bufferSizeThe number of bytes bufferred when reading from and writing to the file
optionsSpecifies how to create or overwrite the file
Returns
A shared pointer to the FileStream object associated with the specified file

◆ CreateText()

static StreamWriterPtr System::IO::File::CreateText ( const String path)
static

Creates a new or opens existing file for writing UTF-8 encoded text.

Parameters
pathThe path of the file to create or open
Returns
A shared pointer to the StreamWriter object associated with the specified file

◆ Decrypt()

static void System::IO::File::Decrypt ( const String path)
static

NOT IMPLEMENTED.

Exceptions
NotImplementedExceptionAlways

◆ Delete()

static void System::IO::File::Delete ( const String path)
static

Deletes the specified file or directory.

Parameters
pathThe path of the file or directory to delete

◆ Encrypt()

static void System::IO::File::Encrypt ( const String path)
static

NOT IMPLEMENTED.

Exceptions
NotImplementedExceptionAlways

◆ Exists()

static bool System::IO::File::Exists ( const String path)
static

Determines if the specified path references an existing file.

Parameters
pathThe path to test
Returns
True if the path references an existing file, otherwise - false

◆ GetAttributes()

static FileAttributes System::IO::File::GetAttributes ( const String path)
static

Returns the attributes of the specified entity.

Parameters
pathThe path of the entity whose attributes to return
Returns
The attributes of the entity referenced by path

◆ GetCreationTime()

static DateTime System::IO::File::GetCreationTime ( const String path)
static

Returns the creation time of the specified entity as local time.

Parameters
pathThe entity whose creating time to retrieve
Returns
A DateTime object representing the creation time of the specified entity as local time

◆ GetCreationTimeUtc()

static DateTime System::IO::File::GetCreationTimeUtc ( const String path)
static

Returns the creation time of the specified entity as UTC time.

Parameters
pathThe entity whose creating time to retrieve
Returns
A DateTime object representing the creation time of the specified entity as UTC time

◆ GetLastAccessTime()

static DateTime System::IO::File::GetLastAccessTime ( const String path)
static

Returns the last access time of the specified entity as local time.

Parameters
pathThe entity whose last access time to retrieve
Returns
A DateTime object representing the last access time of the specified entity as local time

◆ GetLastAccessTimeUtc()

static DateTime System::IO::File::GetLastAccessTimeUtc ( const String path)
static

Returns the last access time of the specified entity as UTC time.

Parameters
pathThe entity whose last access time to retrieve
Returns
A DateTime object representing the last access time of the specified entity as UTC time

◆ GetLastWriteTime()

static DateTime System::IO::File::GetLastWriteTime ( const String path)
static

Returns the last write time of the specified entity as local time.

Parameters
pathThe entity whose last write time to retrieve
Returns
A DateTime object representing the last write time of the specified entity as local time

◆ GetLastWriteTimeUtc()

static DateTime System::IO::File::GetLastWriteTimeUtc ( const String path)
static

Returns the last write time of the specified entity as UTC time.

Parameters
pathThe entity whose last write time to retrieve
Returns
A DateTime object representing the last write time of the specified entity as UTC time

◆ Move()

static void System::IO::File::Move ( const String sourceFileName,
const String destFileName 
)
static

Moves the specified file to the new location.

Parameters
sourceDirNameA file to move
destDirNameThe new location of a file referenced by sourceDirName

◆ Open() [1/2]

static FileStreamPtr System::IO::File::Open ( const String path,
FileMode  mode 
)
static

Opens the specified file in the specified mode for reading and writing and with no sharing.

Parameters
pathThe path of the file to open
modeSpecifies the mode in which to open the flie
Returns
A FileStream object associated with the opened file

◆ Open() [2/2]

static FileStreamPtr System::IO::File::Open ( const String path,
FileMode  mode,
FileAccess  access,
FileShare  share = FileShare::None 
)
static

Opens the specified file in the specified mode, with the specified access type and sharing option.

Parameters
pathThe path of the file to open
modeSpecifies the mode in which to open the flie
accessThe requested access type
shareThe type of access that other FileStream objects have to the opened file
Returns
A FileStream object associated with the opened file

◆ OpenRead()

static FileStreamPtr System::IO::File::OpenRead ( const String path)
static

Opens the specified filefor reading only, in 'Open' mode with shared access for reading.

Parameters
pathThe path of the file to open
Returns
A FileStream object associated with the opened file

◆ OpenText()

static StreamReaderPtr System::IO::File::OpenText ( const String path,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Opens the specified existing file for reading text using UTF-8 encoding with no sharing.

Parameters
pathThe path of the file to open
Returns
A shared pointer to a StreamWriter object associated with the opened file

◆ OpenWrite()

static FileStreamPtr System::IO::File::OpenWrite ( const String path)
static

Opens the specified file for writing only, in 'OpenOrCreate' mode with no sharing.

Parameters
pathThe path of the file to open
Returns
A FileStream object associated with the opened file

◆ ReadAllBytes()

static ArrayPtr<uint8_t> System::IO::File::ReadAllBytes ( const String path)
static

Reads the content of the specified binary file to a byte array.

Parameters
pathThe path of the file to read
Returns
A byte array containing the content of the file

◆ ReadAllLines()

static ArrayPtr<String> System::IO::File::ReadAllLines ( const String path,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Reads the content of the specified text file line by line to an array of strings using the specified character encoding.

Parameters
pathThe path of the file to read
encodingThe character encoding to use
Returns
A string array each element of which represents a single line from the specified file

◆ ReadAllText()

static String System::IO::File::ReadAllText ( const String path,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Reads the content of the specified text file to a single String object using the specified character encoding.

Parameters
pathThe path of the file to read
Returns
A string containing the contet of the specified file

◆ ReadLines()

static SharedPtr<Collections::Generic::IEnumerable<String> > System::IO::File::ReadLines ( const String path,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Reads the content of the specified text file line by line using the specified character encoding and returns enumerable collection of strings each of which represents a single line of the file's content.

Parameters
pathThe path of the file to read
encodingThe character encoding to use
Returns
An anumerable collection of strings representing the content of the specified file

◆ Replace()

static void System::IO::File::Replace ( const String sourceFileName,
const String destinationFileName,
const String destinationBackupFileName,
bool  ignoreMetadataErrors = true 
)
static

TODO.

◆ SetAttributes()

static void System::IO::File::SetAttributes ( const String path,
FileAttributes  fileAttributes 
)
static

Sets the specified attributes on the specified file.

Parameters
pathThe path of the file on which the attributes to be set
fileAttributesA bitwise combination of FileAttributes values representing the attributes to set

◆ SetCreationTime()

static void System::IO::File::SetCreationTime ( const String path,
DateTime  creationTime 
)
static

NOT IMPLEMENTED.

Exceptions
NotImplementedExceptionAlways

◆ SetCreationTimeUtc()

static void System::IO::File::SetCreationTimeUtc ( const String path,
DateTime  creationTimeUtc 
)
static

NOT IMPLEMENTED.

Exceptions
NotImplementedExceptionAlways

◆ SetLastAccessTime()

static void System::IO::File::SetLastAccessTime ( const String path,
DateTime  lastWriteTime 
)
static

NOT IMPLEMENTED.

Exceptions
NotImplementedExceptionAlways

◆ SetLastAccessTimeUtc()

static void System::IO::File::SetLastAccessTimeUtc ( const String path,
DateTime  lastWriteTimeUtc 
)
static

NOT IMPLEMENTED.

Exceptions
NotImplementedExceptionAlways

◆ SetLastWriteTime()

static void System::IO::File::SetLastWriteTime ( const String path,
DateTime  lastWriteTime 
)
static

Sets the last write time of the specified entity as local time.

Parameters
pathThe entity whose last write time to set
dateA DateTime object representing the time to set as local time

◆ SetLastWriteTimeUtc()

static void System::IO::File::SetLastWriteTimeUtc ( const String path,
DateTime  lastWriteTimeUtc 
)
static

Sets the last write time of the specified entity as UTC time.

Parameters
pathThe entity whose last write time to set
dateA DateTime object representing the time to set as UTC time

◆ WriteAllBytes()

static void System::IO::File::WriteAllBytes ( const String path,
const ArrayPtr< uint8_t > &  bytes 
)
static

Overwrites the specified binary file and writes the specified bytes to it.

Parameters
pathThe file to write to
bytesThe byte array containing the bytes to write to the specified file

◆ WriteAllLines() [1/2]

static void System::IO::File::WriteAllLines ( const String path,
const SharedPtr< Collections::Generic::IEnumerable< String >> &  contents,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Creates a new text file or overwrites the existing one and writes all strings from the specified enumerable collection of strings to it, each string on a new line, using the specified encoding.

Parameters
Thefile to create or overwrite
contentsAn enumerable collection of strings
encodingThe character encoding to use

◆ WriteAllLines() [2/2]

static void System::IO::File::WriteAllLines ( const String path,
const ArrayPtr< String > &  contents,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Creates a new text file or overwrites the existing one and writes all strings from the specified array of strings to it, each string on a new line, using the specified encoding.

Parameters
Thefile to create or overwrite
contentsA string array
encodingThe character encoding to use

◆ WriteAllText()

static void System::IO::File::WriteAllText ( const String path,
const String contents,
const EncodingPtr encoding = Text::Encoding::get_UTF8Unmarked() 
)
static

Creates a new text file or overwrites the existing one and writes the content of the specified string to it using the specified encoding.

Parameters
Thefile to create or overwrite
contentsA string array
encodingThe character encoding to use

Member Data Documentation

◆ DefaultBufferSize

const int ASPOSECPP_SHARED_API System::IO::File::DefaultBufferSize
static

Default value of the number of bytes bufferred during reading from and writing to a file.