Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 58 additions & 41 deletions src/Libraries/CoreNodes/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ public static string ReadText(FileInfo file)
/// <summary>
/// Moves a specified file to a new location
/// </summary>
/// <param name="path"></param>
/// <param name="newPath"></param>
/// <param name="overwrite"></param>
/// <param name="path">String representation of existing path</param>
/// <param name="newPath">String representation of new path</param>
/// <param name="overwrite">Toggle to overwrite existing files</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
public static void MoveFile(string path, string newPath, bool overwrite = false)
{
if (overwrite && FileExists(newPath))
Expand All @@ -86,7 +87,8 @@ public static void MoveFile(string path, string newPath, bool overwrite = false)
/// <summary>
/// Deletes the specified file.
/// </summary>
/// <param name="path"></param>
/// <param name="path">File path to delete</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
public static void DeleteFile(string path)
{
System.IO.File.Delete(path);
Expand All @@ -95,9 +97,10 @@ public static void DeleteFile(string path)
/// <summary>
/// Copies a file.
/// </summary>
/// <param name="file"></param>
/// <param name="destinationPath"></param>
/// <param name="overwrite"></param>
/// <param name="file">File object to copy</param>
/// <param name="destinationPath">String representation of destination path</param>
/// <param name="overwrite">Toggle to overwrite existing files</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
public static void CopyFile(FileInfo file, string destinationPath, bool overwrite = false)
{
file.CopyTo(destinationPath, overwrite);
Expand All @@ -106,7 +109,8 @@ public static void CopyFile(FileInfo file, string destinationPath, bool overwrit
/// <summary>
/// Determines if a file exists at the given path.
/// </summary>
/// <param name="path"></param>
/// <param name="path">String representing a file path</param>
/// <returns name="bool">True if file exists, false if it doesn't</returns>
/// <search>filepath</search>
public static bool FileExists(string path)
{
Expand All @@ -131,6 +135,7 @@ public static void WriteText(string filePath, string text)
/// </summary>
/// <param name="filePath">Path to write to</param>
/// <param name="text">Text content</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
/// <search>append file,write file,text,file,filepath</search>
public static void AppendText(string filePath, string text)
{
Expand All @@ -141,16 +146,18 @@ public static void AppendText(string filePath, string text)
/// <summary>
/// Combines multiple strings into a single file path.
/// </summary>
/// <param name="paths">String to combine into a path.</param>
public static string CombinePath(params string[] paths)
/// <param name="strings">Strings to combine into a path</param>
/// <returns name="string">Combined file path</returns>
public static string CombinePath(params string[] strings)
{
return Path.Combine(paths);
return Path.Combine(strings);
}

/// <summary>
/// Returns the extension from a file path.
/// </summary>
/// <param name="path">Path to get extension of.</param>
/// <param name="path">Path to get extension of</param>
/// <returns name="string">Extension of file</returns>
public static string FileExtension(string path)
{
return Path.GetExtension(path);
Expand All @@ -159,8 +166,9 @@ public static string FileExtension(string path)
/// <summary>
/// Changes the extension of a file path.
/// </summary>
/// <param name="path">Path to change extension of.</param>
/// <param name="newExtension">New extension.</param>
/// <param name="path">Path to change extension of</param>
/// <param name="newExtension">String representation of new extension</param>
/// <returns name="string">File path with changed extension</returns>
public static string ChangePathExtension(string path, string newExtension)
{
return Path.ChangeExtension(path, newExtension);
Expand All @@ -169,7 +177,8 @@ public static string ChangePathExtension(string path, string newExtension)
/// <summary>
/// Returns the directory name of a file path.
/// </summary>
/// <param name="path">Path to get directory information of.</param>
/// <param name="path">Path to get directory information of</param>
/// <returns name="string">Directory name of file path</returns>
/// <search>directorypath</search>
public static string DirectoryName(string path)
{
Expand All @@ -179,8 +188,9 @@ public static string DirectoryName(string path)
/// <summary>
/// Returns the file name of a file path.
/// </summary>
/// <param name="path">Path to get the file name of.</param>
/// <param name="withExtension">Determines whether or not the extension is included in the result, defaults to true.</param>
/// <param name="path">Path to get the file name of</param>
/// <param name="withExtension">Toggle to include extension in result</param>
/// <returns name="bool">File name from file path</returns>
public static string FileName(string path, bool withExtension = true)
{
return withExtension ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path);
Expand All @@ -189,18 +199,21 @@ public static string FileName(string path, bool withExtension = true)
/// <summary>
/// Determines whether or not a file path contains an extension.
/// </summary>
/// <param name="path">Path to check for an extension.</param>
/// <param name="path">Path to check for an extension</param>
/// <returns name="bool">True if file path contains extension, false if it doesn't</returns>
public static bool FileHasExtension(string path)
{
return Path.HasExtension(path);
}

/// <summary>
/// Returns all of the contents of a given directory.
/// <summary>
/// Will return a list of files and directories that are contained within a given directory. An optional searchString can be used to filter the results.
/// </summary>
/// <param name="directory">Directory to get contents of.</param>
/// <param name="searchString">Search string used to filter results. Defaults to "*.*" (displays all contents).</param>
/// <param name="includeSubdirectories">Set to true to include files & folders in subdirectories (recursive) or set to false to include results from top-level of given directory only. Defaults to false.</param>
/// <param name="directory">Directory to get contents of</param>
/// <param name="searchString">Search string used to filter results</param>
/// <param name="includeSubdirectories">Set to true to include files and folders in subdirectories (recursive) or set to false to include results from top-level of given directory only.</param>
/// <returns name="files">Resulting files from query</returns>
/// <returns name="directories">Resulting directories from query</returns>
[MultiReturn("files", "directories")]
public static Dictionary<string, IList> GetDirectoryContents(DirectoryInfo directory, string searchString = "*.*", bool includeSubdirectories = false)
{
Expand All @@ -219,9 +232,10 @@ public static Dictionary<string, IList> GetDirectoryContents(DirectoryInfo direc
/// <summary>
/// Copies a directory to a destination location.
/// </summary>
/// <param name="directory">Directory to copy.</param>
/// <param name="destinationPath">Destination of the copy operation on disk.</param>
/// <param name="overwriteFiles"></param>
/// <param name="directory">Directory to copy</param>
/// <param name="destinationPath">Destination of the copy operation on disk</param>
/// <param name="overwriteFiles">Toggle to overwrite existing directory</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
public static void CopyDirectory(DirectoryInfo directory, string destinationPath, bool overwriteFiles = false)
{
if (!FileExists(destinationPath))
Expand All @@ -243,8 +257,9 @@ public static void CopyDirectory(DirectoryInfo directory, string destinationPath
/// <summary>
/// Deletes a directory.
/// </summary>
/// <param name="path">Path to a directory on disk.</param>
/// <param name="path">Path to a directory on disk</param>
/// <param name="recursive">Whether or not to delete all contents of the directory, defaults to false.</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
public static void DeleteDirectory(string path, bool recursive = false)
{
Directory.Delete(path, recursive);
Expand All @@ -253,7 +268,8 @@ public static void DeleteDirectory(string path, bool recursive = false)
/// <summary>
/// Determines if a directory exists at the given path.
/// </summary>
/// <param name="path">Path to a directory on disk.</param>
/// <param name="path">Path to a directory on disk</param>
/// <returns name="bool">True if directory exists, false if it doesn’t</returns>
/// <search>directorypath</search>
public static bool DirectoryExists(string path)
{
Expand All @@ -270,9 +286,10 @@ public static DirectoryInfo DirectoryFromPath(string path)
/// <summary>
/// Moves a directory to a new location.
/// </summary>
/// <param name="path"></param>
/// <param name="newPath"></param>
/// <param name="overwriteFiles"></param>
/// <param name="path">String representation of existing path</param>
/// <param name="newPath">String representation of new path</param>
/// <param name="overwriteFiles">Toggle to overwrite existing files</param>
/// <returns name="void">Node performs a task, doesn’t produce an output </returns>
public static void MoveDirectory(string path, string newPath, bool overwriteFiles = false)
{
if (!DirectoryExists(newPath))
Expand Down Expand Up @@ -343,8 +360,8 @@ public static class Image
/// <summary>
/// Loads the file as a bitmap.
/// </summary>
/// <param name="file">File object to load image from.</param>
/// <returns name="image">Image</returns>
/// <param name="file">File object to load image from</param>
/// <returns name="image">Image object from file</returns>
public static Bitmap ReadFromFile(FileInfo file)
{
using (var fs = new FileStream(file.FullName, FileMode.Open))
Expand All @@ -354,10 +371,10 @@ public static Bitmap ReadFromFile(FileInfo file)
/// <summary>
/// Reads an image file and returns the color values at the specified grid locations.
/// </summary>
/// <param name="image">The image to read.</param>
/// <param name="image">Image object to get pixel colors from</param>
/// <param name="xSamples">Number of sample grid points in the X direction.</param>
/// <param name="ySamples">Number of sample grid points in the Y direction.</param>
/// <returns name="colors">Colors at the specified grid points.</returns>
/// <returns name="colors">Colors at the specified grid points</returns>
/// <search>read,image,bitmap,png,jpg,jpeg</search>
public static Color[][] Pixels(Bitmap image, int? xSamples = null, int? ySamples = null)
{
Expand All @@ -381,8 +398,8 @@ public static Color[][] Pixels(Bitmap image, int? xSamples = null, int? ySamples
/// <summary>
/// Constructs an image from a 2d list of pixels.
/// </summary>
/// <param name="colors">2d rectangular list of colors representing the pixels.</param>
/// <returns name="image">Image</returns>
/// <param name="colors">2d rectangular list of colors representing the pixels</param>
/// <returns name="image">Image from 2d list of pixels</returns>
public static Bitmap FromPixels(Color[][] colors)
{
var height = colors.Length;
Expand All @@ -396,10 +413,10 @@ public static Bitmap FromPixels(Color[][] colors)
/// <summary>
/// Constructs an image from a flat list of pixels, a width, and a height.
/// </summary>
/// <param name="colors">List of colors representing the pixels.</param>
/// <param name="width">Width of the new image, in pixels.</param>
/// <param name="height">Height of the new image, in pixels.</param>
/// <returns name="image">Image</returns>
/// <param name="colors">List of colors representing the pixels</param>
/// <param name="width">Width of the new image, in pixels</param>
/// <param name="height">Height of the new image, in pixels</param>
/// <returns name="image">Image from list of pixels</returns>
public static Bitmap FromPixels(Color[] colors, int width, int height)
{
return FromPixelsHelper(colors, width, height);
Expand Down