FileSystem

Assembly: ZennoLab.Macros
Full name: ZennoLab.Macros.FileSystem
Kind: abstract


Represents the static methods for working with file system.

Methods

DirectoryCountOfFiles

Method

int DirectoryCountOfFiles(string pathToDirectory)

Gets count of files in the directory

Parameters

TypeNameDescription
stringpathToDirectoryPath to the directory.

Returns: Count of files in the directory.

Example

string pathToDirectory = {pathToDirectory};
            int countOfFiles = FileSystem.DirectoryCountOfFiles(pathToDirectory);

Example2

$pathToDirectory = {pathToDirectory};
            $countOfFiles = FileSystem::DirectoryCountOfFiles($pathToDirectory);

DirectoryRandomFile

Method

string DirectoryRandomFile(string pathToDirectory)

Get the random file in the directory

Parameters

TypeNameDescription
stringpathToDirectoryPath to the directory.

Returns: Path to the random file in the directory.

Example

string pathToDirectory = {pathToDirectory};
            string resultFilePath = FileSystem.DirectoryRandomFile(pathToDirectory);

Example2

$pathToDirectory = {pathToDirectory};
            $resultFilePath = FileSystem::DirectoryRandomFile($pathToDirectory);

DirectorySubItem

Method

string DirectorySubItem(string pathToDirectory, string items, string itemNumber, bool sortAlphabetically)

The path to a file/subdirectory in the specified directory

Parameters

TypeNameDescription
stringpathToDirectoryPath to the directory.
stringitemsSampling units (“d” - directories, “f” - files, “df” - all together) .
stringitemNumberThe number of the element.
boolsortAlphabeticallytrue if sort items before sampling; otherwise, false.

Returns: Directory entries .

Example

string pathToDirectory = {pathToDirectory};
            string items = "df";
            string itemNumber = "0";
            bool sortAlphabetically = false;
            string result = FileSystem.DirectorySubItem(pathToDirectory, items, itemNumber, sortAlphabetically);

Example2

$pathToDirectory = {pathToDirectory};
            $items = "df";
            $itemNumber = "0";
            $sortAlphabetically = false;
            $result = FileSystem::DirectorySubItem($pathToDirectory, $items, $itemNumber, $sortAlphabetically);

DirectoryDeleteFileByMask

Method

void DirectoryDeleteFileByMask(string pathToDirectory, string pattern)

Removes the file by mask

Parameters

TypeNameDescription
stringpathToDirectoryPath to the directory.
stringpatternMask for remove files .

Example

string pathToDirectory = {pathToDirectory};
            string pattern = {maskToRemoveFiles};
            FileSystem.DirectoryDeleteFileByMask(pathToDirectory, pattern);

Example2

$pathToDirectory = {pathToDirectory};
            $pattern = {maskToRemoveFiles};
            FileSystem::DirectoryDeleteFileByMask($pathToDirectory, $pattern);

DirectoryDeleteFile

Method

void DirectoryDeleteFile(string pathToFile)

Removes the file

Parameters

TypeNameDescription
stringpathToFilePath to the file.

Example

string pathToFile = {pathToFile};
            FileSystem.DirectoryDeleteFile(pathToFile);

Example2

$pathToFile = {pathToFile};
            FileSystem::DirectoryDeleteFile($pathToFile);

DirectoryDeleteDirectory

Method

void DirectoryDeleteDirectory(string pathToDirectory, bool recursive, bool onlyFromStartupPath)

Remove target directory

Parameters

TypeNameDescription
stringpathToDirectoryPath to the directory.
boolrecursivetrue if removingrecursively; otherwise, false.
boolonlyFromStartupPathtrue if not removethe directorydoes notbelong tothe startup directory; otherwise, false.

Example

string pathToDirectory = {pathToDirectory};
            bool recursive = true;
            bool startupPath = false;
            FileSystem.DirectoryDeleteDirectory(pathToDirectory, recursive, startupPath);

Example2

$pathToDirectory = {pathToDirectory};
            $recursive = true;
            $startupPath = false;
            FileSystem::DirectoryDeleteDirectory($pathToDirectory, $recursive, $startupPath);

FileGetLine

Method

string FileGetLine(string path, string numberOfLine, bool removeLine, bool removeEmptyFile)

Gets string from the file

Parameters

TypeNameDescription
stringpathPath to the source file.
stringnumberOfLineThe number of the line.
boolremoveLinetrue if remove the used line; otherwise, false.
boolremoveEmptyFiletrue if need to remove empty source file after sampling; otherwise, false.

Returns: String after spliting and sampling.

Example

string path = {pathToFile};
            string numberOfLine = {numberOfLine};
            bool removeLine = true;
            string result = FileSystem.FileGetLine(path, numberOfLine, removeLine);

Example2

$path = {pathToFile};
            $numberOfLine = {numberOfLine};
            $removeLine = true;
            $result = FileSystem::FileGetLine($path, $numberOfLine, $removeLine);

FileGetLines

Method

String[] FileGetLines(string path, string numberOfLine, bool removeLine, bool removeEmptyFile)

Gets strings from the file

Parameters

TypeNameDescription
stringpathPath to the source file.
stringnumberOfLineThe number of the line.
boolremoveLinetrue if remove the used line; otherwise, false.
boolremoveEmptyFiletrue if need to remove empty source file after sampling; otherwise, false.

Returns: Strings after spliting and sampling.

Example

string path = {pathToFile};
            string numberOfLine = {numberOfLine};
            bool removeLine = true;
            string[] result = FileSystem.FileGetLines(path, numberOfLine, removeLine);

Example2

$path = {pathToFile};
            $numberOfLine = {numberOfLine};
            $removeLine = true;
            $result = FileSystem::FileGetLines($path, $numberOfLine, $removeLine);

FileGetLine

Method

string FileGetLine(string path, string numberOfLine, bool removeLine, string regex, string numberOfMatch, bool removeEmptyFile)

Gets string from the file

Parameters

TypeNameDescription
stringpathPath to the source file.
stringnumberOfLineThe number of the line.
boolremoveLinetrue if remove the used line; otherwise, false.
stringregexRegular expression to parse the line.
stringnumberOfMatchNumber of match after parsing.
boolremoveEmptyFiletrue if need to remove empty source file after sampling; otherwise, false.

Returns: String after spliting and sampling.

Example

string path = {pathToFile};
            string numberOfLine = {numberOfLine};
            bool removeLine = true;
            string regex = {regularExpression};
            string numberOfMatch = {numberOfMatch};
            string result = FileSystem.FileGetLine(path, numberOfLine, removeLine, regex, numberOfMatch);

Example2

$path = {pathToFile};
            $numberOfLine = {numberOfLine};
            $removeLine = true;
            $regex = {regularExpression};
            $numberOfMatch = {numberOfMatch};
            $result = FileSystem::FileGetLine($path, $numberOfLine, $removeLine, $regex, $numberOfMatch);

FileGetLines

Method

String[] FileGetLines(string path, string numberOfLine, bool removeLine, string regex, string numberOfMatch, bool removeEmptyFile)

Gets strings from the file

Parameters

TypeNameDescription
stringpathPath to the source file.
stringnumberOfLineThe number of the line.
boolremoveLinetrue if remove the used line; otherwise, false.
stringregexRegular expression to parse the line.
stringnumberOfMatchNumber of match after parsing.
boolremoveEmptyFiletrue if need to remove empty source file after sampling; otherwise, false.

Returns: Strings after spliting and sampling.

Example

string path = {pathToFile};
            string numberOfLine = {numberOfLine};
            bool removeLine = true;
            string regex = {regularExpression};
            string numberOfMatch = {numberOfMatch};
            string[] result = FileSystem.FileGetLines(path, numberOfLine, removeLine, regex, numberOfMatch);

Example2

$path = {pathToFile};
            $numberOfLine = {numberOfLine};
            $removeLine = true;
            $regex = {regularExpression};
            $numberOfMatch = {numberOfMatch};
            $result = FileSystem::FileGetLines($path, $numberOfLine, $removeLine, $regex, $numberOfMatch);

FileGetBlock

Method

string FileGetBlock(string path, string blockSplitter, string numberOfLine, bool removeBlock, bool removeEmptyFile)

Gets text block from the file

Parameters

TypeNameDescription
stringpathPath to the source file.
stringblockSplitterDelimiter for text in the file.
stringnumberOfLineThe line number after splitting into blocks.
boolremoveBlocktrue if remove the used block; otherwise, false.
boolremoveEmptyFiletrue if need to remove empty source file after sampling; otherwise, false.

Returns: Text block after spliting and sampling.

Example

string path = {pathToFile};
            string blockSplitter = ":";
            string numberOfLine = "random";
            bool removeBlock = false;
            string result = FileSystem.FileGetBlock(path, blockSplitter, numberOfLine, removeBlock);

Example2

$path = {pathToFile};
            $blockSplitter = ":";
            $numberOfLine = "random";
            $removeBlock = false;
            $result = FileSystem::FileGetBlock($path, $blockSplitter, $numberOfLine, $removeBlock);

FileGetBlocks

Method

String[] FileGetBlocks(string path, string blockSplitter, string numberOfLine, bool removeBlock, bool removeEmptyFile)

Gets text blocks from the file

Parameters

TypeNameDescription
stringpathPath to the source file.
stringblockSplitterDelimiter for text in the file.
stringnumberOfLineThe line number after splitting into blocks.
boolremoveBlocktrue if remove the used block; otherwise, false.
boolremoveEmptyFiletrue if need to remove empty source file after sampling; otherwise, false.

Returns: Text blocks after spliting and sampling.

Example

string path = {pathToFile};
            string blockSplitter = ":";
            string numberOfLine = "all";
            bool removeBlock = false;
            string[] result = FileSystem.FileGetBlocks(path, blockSplitter, numberOfLine, removeBlock);

Example2

$path = {pathToFile};
            $blockSplitter = ":";
            $numberOfLine = "all";
            $removeBlock = false;
            $result = FileSystem::FileGetBlocks($path, $blockSplitter, $numberOfLine, $removeBlock);

FileAppendString

Method

void FileAppendString(string path, string text, bool appendNewLine)

Appends line to the end of file

Parameters

TypeNameDescription
stringpathPath to the file.
stringtextText to append.
boolappendNewLinetrue if append text in a new line; otherwise, false.

Example

string path = {pathToFile};
            string text = "it is new line in the file!";
            bool appendNewLine = true;
            FileSystem.FileAppendString(path, text, appendNewLine);

Example2

$path = {pathToFile};
            $text = "it is new line in the file!";
            $appendNewLine = true;
            FileSystem::FileAppendString($path, $text, $appendNewLine);

FileCountOfLines

Method

string FileCountOfLines(string path)

Get count of lines in the file

Parameters

TypeNameDescription
stringpathPath to the file.

Returns: Count of lines in the file.

Example

string path = {pathToFile};
            string countOfLines = FileSystem.FileCountOfLines(path);

Example2

$path = {pathToFile};
            $countOfLines = FileSystem::FileCountOfLines($path);

FileCopy

Method

void FileCopy(string oldPath, string newPath)

Copies an existing file

Parameters

TypeNameDescription
stringoldPathPath to the existing file.
stringnewPathPath to the new file.

Example

string oldPath = {pathToExistingFile};
            string newPath = {pathToNewFile};
            FileSystem.FileCopy(oldPath, newPath);

Example2

$oldPath = {pathToExistingFile};
            $newPath = {pathToNewFile};
            FileSystem::FileCopy($oldPath, $newPath);