FileSystem

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


Represents the static methods for working with file system.

Methods

IsSystemFolder

Method

Проверяем лежит ли файл в папке системы

Parameters

ПараметрОписание
pathпуть

DirectoryCountOfFiles

Method

Gets count of files in the directory

Parameters

ПараметрОписание
pathToDirectoryPath 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

Get the random file in the directory

Parameters

ПараметрОписание
pathToDirectoryPath 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

The path to a file/subdirectory in the specified directory

Parameters

ПараметрОписание
pathToDirectoryPath to the directory.
itemsSampling units (“d” - directories, “f” - files, “df” - all together) .
itemNumberThe number of the element.
sortAlphabeticallytrue 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

Removes the file by mask

Parameters

ПараметрОписание
pathToDirectoryPath to the directory.
patternMask 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

Removes the file

Parameters

ПараметрОписание
pathToFilePath to the file.

Example

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

Example2

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

DirectoryDeleteDirectory

Method

Remove target directory

Parameters

ПараметрОписание
pathToDirectoryPath to the directory.
recursivetrue if removingrecursively; otherwise, false.
onlyFromStartupPathtrue 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);

GetFileStream

Method

get exclusive file stream

Parameters

ПараметрОписание
pathpath to the file
existCheck
fileMode

Returns: stream

RemoveAndWrite

Method

Удалить строку и записать в поток

Parameters

ПараметрОписание
fsпоток
textтекст
lineстрока для удаления

RemoveAndWrite

Method

Удалить строку и записать в поток

Parameters

ПараметрОписание
fsпоток
textтекст
linesстроки для удаления

FileGetLine

Method

Gets string from the file

Parameters

ПараметрОписание
pathPath to the source file.
numberOfLineThe number of the line.
removeLinetrue if remove the used line; otherwise, false.
removeEmptyFiletrue 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

Gets strings from the file

Parameters

ПараметрОписание
pathPath to the source file.
numberOfLineThe number of the line.
removeLinetrue if remove the used line; otherwise, false.
removeEmptyFiletrue 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

Gets string from the file

Parameters

ПараметрОписание
pathPath to the source file.
numberOfLineThe number of the line.
removeLinetrue if remove the used line; otherwise, false.
regexRegular expression to parse the line.
numberOfMatchNumber of match after parsing.
removeEmptyFiletrue 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

Gets strings from the file

Parameters

ПараметрОписание
pathPath to the source file.
numberOfLineThe number of the line.
removeLinetrue if remove the used line; otherwise, false.
regexRegular expression to parse the line.
numberOfMatchNumber of match after parsing.
removeEmptyFiletrue 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

Gets text block from the file

Parameters

ПараметрОписание
pathPath to the source file.
blockSplitterDelimiter for text in the file.
numberOfLineThe line number after splitting into blocks.
removeBlocktrue if remove the used block; otherwise, false.
removeEmptyFiletrue 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

Gets text blocks from the file

Parameters

ПараметрОписание
pathPath to the source file.
blockSplitterDelimiter for text in the file.
numberOfLineThe line number after splitting into blocks.
removeBlocktrue if remove the used block; otherwise, false.
removeEmptyFiletrue 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

Appends line to the end of file

Parameters

ПараметрОписание
pathPath to the file.
textText to append.
appendNewLinetrue 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

Get count of lines in the file

Parameters

ПараметрОписание
pathPath 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

Copies an existing file

Parameters

ПараметрОписание
oldPathPath to the existing file.
newPathPath to the new file.

Example

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

Example2

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