Joutsen v0.5.0+12-g5dd5f7e
Public Member Functions | Properties | List of all members
Joutsen.IO.LocalFile Class Reference

A class representing a file in the file system. More...

Public Member Functions

 LocalFile (string path)
 Creates a new File instance for a path. More...
 
 LocalFile (LocalFilesystemPath path)
 Creates a new File instance for a path represented by a string. More...
 
void Create ()
 Creates the file without content. More...
 
void Create (SystemIO.Stream contents)
 Creates the file with content. More...
 
SystemIO.Stream CreateAndOpen ()
 Creates the file on the filesystem and opens it for writing. More...
 
SystemIO.Stream Open (SystemIO.FileMode mode)
 Opens the file for reading or writing. More...
 
File CopyTo (string dstPath, bool overwrite=false)
 Copies the file to a different path. More...
 
File CopyTo (FilesystemPath dstPath, bool overwrite=false)
 Copies the file to a different path. More...
 
File MoveTo (string dstPath)
 Moves the file to a different location. More...
 
File MoveTo (FilesystemPath dstPath)
 Moves the file to a different location. More...
 
File MoveTo (File dstFile)
 
void Delete ()
 Deletes the file on from the filesystem. More...
 
File Replace (string dstPath, string backupPath)
 Replaces the file at dstPath with this file creating a backup in backupPath. More...
 
File Replace (FilesystemPath dstPath, FilesystemPath backupPath)
 Replaces the file at dstPath with this file creating a backup in backupPath. More...
 
File Replace (File dstFile, File backup)
 Replaces the file at dstFile with this file creating a backup in backup. More...
 
File ReplaceWith (string srcPath, string backupPath)
 Replace this file's content with the content of the file at @psrcPath. More...
 
File ReplaceWith (FilesystemPath srcPath, FilesystemPath backupPath)
 Replace this file's content with the content of the file at @psrcPath. More...
 
File ReplaceWith (File srcFile, File backup)
 Replace this file's content with the content of srcFile. More...
 
override bool Equals (object obj)
 Compares this instance to another one for equality. More...
 
override int GetHashCode ()
 Calculates the hash code for this instance. More...
 
override string ToString ()
 Creates a string representation of this file instance. More...
 
void Create ()
 Creates the file without content. More...
 
void Create (SystemIO.Stream contents)
 Creates the file with content. More...
 
SystemIO.Stream CreateAndOpen ()
 Creates the file on the filesystem and opens it for writing. More...
 
SystemIO.Stream Open (SystemIO.FileMode mode)
 Opens the file for reading or writing. More...
 
File CopyTo (string dstPath, bool overwrite=false)
 Copies the file to a different path. More...
 
File CopyTo (FilesystemPath dstPath, bool overwrite=false)
 Copies the file to a different path. More...
 
File MoveTo (string dstPath)
 Moves the file to a different location. More...
 
File MoveTo (FilesystemPath dstPath)
 Moves the file to a different location. More...
 
void Delete ()
 Deletes the file on from the filesystem. More...
 
File Replace (string dstPath, string backupPath)
 Replaces the file at dstPath with this file creating a backup in backupPath. More...
 
File Replace (FilesystemPath dstPath, FilesystemPath backupPath)
 Replaces the file at dstPath with this file creating a backup in backupPath. More...
 
File Replace (File dstFile, File backup)
 Replaces the file at dstFile with this file creating a backup in backup. More...
 
File ReplaceWith (string srcPath, string backupPath)
 Replace this file's content with the content of the file at @psrcPath. More...
 
File ReplaceWith (FilesystemPath srcPath, FilesystemPath backupPath)
 Replace this file's content with the content of the file at @psrcPath. More...
 
File ReplaceWith (File srcFile, File backup)
 Replace this file's content with the content of srcFile. More...
 

Properties

String Name [get]
 The name of the file. More...
 
String Extension [get]
 The extension of the file. More...
 
LocalFilesystemPath Path [get]
 The path of the file. More...
 
LocalFolder Folder [get]
 The path of the file. More...
 
DateTime LastModificationTime [get]
 The time the file was last changed. More...
 
DateTime CreationTime [get]
 The time the file was created. More...
 
bool Exists [get]
 Checks if the file exists in the filesystem. More...
 
bool IsWritable [get]
 Checks if the file is writable in the filesystem. More...
 
- Properties inherited from Joutsen.IO.File
String Name [get]
 
String Extension [get]
 The extension of the file. More...
 
FilesystemPath Path [get]
 The path of the file. More...
 
Folder Folder [get]
 The folder where the file is located. More...
 
DateTime LastModificationTime [get]
 The time the file was last changed. More...
 
DateTime CreationTime [get]
 The time the file was created. More...
 
bool Exists [get]
 Checks if the file exists in the filesystem. More...
 
bool IsWritable [get]
 Checks if the file is writable in the filesystem. More...
 

Detailed Description

A class representing a file in the file system.

Remarks
The file does not have to exist. It can also be a potential file.
Since
0.4.0

Constructor & Destructor Documentation

◆ LocalFile() [1/2]

Joutsen.IO.LocalFile.LocalFile ( string  path)

Creates a new File instance for a path.

Parameters
paththe path to the file. Can be absolute or relative.
Exceptions
System.ArgumentNullExceptionif path is null
System.ArgumentExceptionif path is empty or leads to a folder

◆ LocalFile() [2/2]

Joutsen.IO.LocalFile.LocalFile ( LocalFilesystemPath  path)

Creates a new File instance for a path represented by a string.

Parameters
paththe path to the file. Can be absolute or relative.
Exceptions
System.ArgumentNullExceptionif @path is null
System.ArgumentExceptionif path leads to a folder

Member Function Documentation

◆ CopyTo() [1/2]

File Joutsen.IO.LocalFile.CopyTo ( FilesystemPath  dstPath,
bool  overwrite = false 
)

Copies the file to a different path.

Parameters
dstPaththe path to copy the file to
overwritedetermines if an existing file at dstPath should be overwritten
Returns
the file representing the copy
Exceptions
System.ArgumentNullExceptionif dstPath is null

Implements Joutsen.IO.File.

◆ CopyTo() [2/2]

File Joutsen.IO.LocalFile.CopyTo ( string  dstPath,
bool  overwrite = false 
)

Copies the file to a different path.

Parameters
dstPaththe path to copy the file to
overwritedetermines if an existing file at dstPath should be overwritten
Returns
the file representing the copy

Implements Joutsen.IO.File.

◆ Create() [1/2]

void Joutsen.IO.LocalFile.Create ( )

Creates the file without content.

Implements Joutsen.IO.File.

◆ Create() [2/2]

void Joutsen.IO.LocalFile.Create ( SystemIO.Stream  contents)

Creates the file with content.

Parameters
contentthe content that should be written to the new file

Implements Joutsen.IO.File.

◆ CreateAndOpen()

SystemIO.Stream Joutsen.IO.LocalFile.CreateAndOpen ( )

Creates the file on the filesystem and opens it for writing.

Returns
the open stream which can be used to write to the file
Remarks
The caller has to take care of closing the stream.

Implements Joutsen.IO.File.

◆ Delete()

void Joutsen.IO.LocalFile.Delete ( )

Deletes the file on from the filesystem.

Implements Joutsen.IO.File.

◆ Equals()

override bool Joutsen.IO.LocalFile.Equals ( object  obj)

Compares this instance to another one for equality.

Parameters
objthe instance to check for equality

◆ GetHashCode()

override int Joutsen.IO.LocalFile.GetHashCode ( )

Calculates the hash code for this instance.

◆ MoveTo() [1/3]

File Joutsen.IO.LocalFile.MoveTo ( File  dstFile)

◆ MoveTo() [2/3]

File Joutsen.IO.LocalFile.MoveTo ( FilesystemPath  dstPath)

Moves the file to a different location.

Parameters
dstPaththe path to move the file to
Returns
the file representing the moved file
Exceptions
System.ArgumentNullExceptionif dstPath is null

Implements Joutsen.IO.File.

◆ MoveTo() [3/3]

File Joutsen.IO.LocalFile.MoveTo ( string  dstPath)

Moves the file to a different location.

Parameters
dstPaththe path to move the file to
Returns
the file representing the moved file

Implements Joutsen.IO.File.

◆ Open()

SystemIO.Stream Joutsen.IO.LocalFile.Open ( SystemIO.FileMode  mode)

Opens the file for reading or writing.

Parameters
modedetermines if the file is opened for reading or writing
Returns
a stream representing the files content
Remarks
The stream is not closed automatically. The caller needs to take care of properly closing it.

Implements Joutsen.IO.File.

◆ Replace() [1/3]

File Joutsen.IO.LocalFile.Replace ( File  dstFile,
File  backup 
)

Replaces the file at dstFile with this file creating a backup in backup.

Parameters
dstFilethe file that should be replaced
backupthe file where the backup of dstFile should be stored
Returns
a file representing the backup of the replaced file or null if no backup is created
Exceptions
System.ArgumentNullExceptionif dstFile is null
Remarks
If null is passed as backup, no backup is created.

Implements Joutsen.IO.File.

◆ Replace() [2/3]

File Joutsen.IO.LocalFile.Replace ( FilesystemPath  dstPath,
FilesystemPath  backupPath 
)

Replaces the file at dstPath with this file creating a backup in backupPath.

Parameters
dstpaththe path to the file that should be replaced
backupPaththe path to the location where the backup of the file at dstPath should be stored
Returns
a file representing the backup of the replaced file or null if no backup is created
Exceptions
System.ArgumentNullExceptionif dstPath is null
Remarks
If null is passed as backupPath, no backup is created. The original file is deleted by this method.

Implements Joutsen.IO.File.

◆ Replace() [3/3]

File Joutsen.IO.LocalFile.Replace ( string  dstPath,
string  backupPath 
)

Replaces the file at dstPath with this file creating a backup in backupPath.

Parameters
dstpaththe path to the file that should be replaced
backupPaththe path to the location where the backup of the file at dstPath should be stored
Returns
a file representing the backup of the replaced file or null if no backup is created
Remarks
If null is passed as backupPath, no backup is created. The original file is deleted by this method.

Implements Joutsen.IO.File.

◆ ReplaceWith() [1/3]

File Joutsen.IO.LocalFile.ReplaceWith ( File  srcFile,
File  backup 
)

Replace this file's content with the content of srcFile.

Parameters
srcFilethe file that contains the content which should replace this file
backupthe file where the backup of this file should be stored
Returns
a file representing the backup of this file or null if no backup is created
Exceptions
System.ArgumentNullExceptionif srcFile is null
Remarks
If null is passed as backup, no backup is created.

Implements Joutsen.IO.File.

◆ ReplaceWith() [2/3]

File Joutsen.IO.LocalFile.ReplaceWith ( FilesystemPath  srcPath,
FilesystemPath  backupPath 
)

Replace this file's content with the content of the file at @psrcPath.

Parameters
srcPaththe path to the file that contains the content which should replace this file
backupthe file where the backup of this file should be stored
Returns
a file representing the backup of this file or null if no backup is created
Exceptions
System.ArgumentNullExceptionif srcFile is null
Remarks
If null is passed as backup, no backup is created.

Implements Joutsen.IO.File.

◆ ReplaceWith() [3/3]

File Joutsen.IO.LocalFile.ReplaceWith ( string  srcPath,
string  backupPath 
)

Replace this file's content with the content of the file at @psrcPath.

Parameters
srcPaththe path to the file that contains the content which should replace this file
backupthe file where the backup of this file should be stored
Returns
a file representing the backup of this file or null if no backup is created
Exceptions
System.ArgumentNullExceptionif srcFile is null
Remarks
If null is passed as backup, no backup is created.

Implements Joutsen.IO.File.

◆ ToString()

override string Joutsen.IO.LocalFile.ToString ( )

Creates a string representation of this file instance.

Property Documentation

◆ CreationTime

DateTime Joutsen.IO.LocalFile.CreationTime
get

The time the file was created.

Implements Joutsen.IO.File.

◆ Exists

bool Joutsen.IO.LocalFile.Exists
get

Checks if the file exists in the filesystem.

Implements Joutsen.IO.File.

◆ Extension

String Joutsen.IO.LocalFile.Extension
get

The extension of the file.

Implements Joutsen.IO.File.

◆ Folder

LocalFolder Joutsen.IO.LocalFile.Folder
get

The path of the file.

Implements Joutsen.IO.File.

◆ IsWritable

bool Joutsen.IO.LocalFile.IsWritable
get

Checks if the file is writable in the filesystem.

Implements Joutsen.IO.File.

◆ LastModificationTime

DateTime Joutsen.IO.LocalFile.LastModificationTime
get

The time the file was last changed.

Implements Joutsen.IO.File.

◆ Name

String Joutsen.IO.LocalFile.Name
get

The name of the file.

Implements Joutsen.IO.File.

◆ Path

LocalFilesystemPath Joutsen.IO.LocalFile.Path
get

The path of the file.

Implements Joutsen.IO.File.