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
| Параметр | Описание |
|---|---|
pathToDirectory | Path 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
| Параметр | Описание |
|---|---|
pathToDirectory | Path 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
| Параметр | Описание |
|---|---|
pathToDirectory | Path to the directory. |
items | Sampling units (“d” - directories, “f” - files, “df” - all together) . |
itemNumber | The number of the element. |
sortAlphabetically | true 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
| Параметр | Описание |
|---|---|
pathToDirectory | Path to the directory. |
pattern | Mask 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
| Параметр | Описание |
|---|---|
pathToFile | Path to the file. |
Example
string pathToFile = {pathToFile};
FileSystem.DirectoryDeleteFile(pathToFile);Example2
$pathToFile = {pathToFile};
FileSystem::DirectoryDeleteFile($pathToFile);DirectoryDeleteDirectory
Method
Remove target directory
Parameters
| Параметр | Описание |
|---|---|
pathToDirectory | Path to the directory. |
recursive | true if removingrecursively; otherwise, false. |
onlyFromStartupPath | true 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
| Параметр | Описание |
|---|---|
path | path 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
| Параметр | Описание |
|---|---|
path | Path to the source file. |
numberOfLine | The number of the line. |
removeLine | true if remove the used line; otherwise, false. |
removeEmptyFile | true 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
| Параметр | Описание |
|---|---|
path | Path to the source file. |
numberOfLine | The number of the line. |
removeLine | true if remove the used line; otherwise, false. |
removeEmptyFile | true 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
| Параметр | Описание |
|---|---|
path | Path to the source file. |
numberOfLine | The number of the line. |
removeLine | true if remove the used line; otherwise, false. |
regex | Regular expression to parse the line. |
numberOfMatch | Number of match after parsing. |
removeEmptyFile | true 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
| Параметр | Описание |
|---|---|
path | Path to the source file. |
numberOfLine | The number of the line. |
removeLine | true if remove the used line; otherwise, false. |
regex | Regular expression to parse the line. |
numberOfMatch | Number of match after parsing. |
removeEmptyFile | true 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
| Параметр | Описание |
|---|---|
path | Path to the source file. |
blockSplitter | Delimiter for text in the file. |
numberOfLine | The line number after splitting into blocks. |
removeBlock | true if remove the used block; otherwise, false. |
removeEmptyFile | true 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
| Параметр | Описание |
|---|---|
path | Path to the source file. |
blockSplitter | Delimiter for text in the file. |
numberOfLine | The line number after splitting into blocks. |
removeBlock | true if remove the used block; otherwise, false. |
removeEmptyFile | true 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
| Параметр | Описание |
|---|---|
path | Path to the file. |
text | Text to append. |
appendNewLine | true 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
| Параметр | Описание |
|---|---|
path | Path 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
| Параметр | Описание |
|---|---|
oldPath | Path to the existing file. |
newPath | Path to the new file. |
Example
string oldPath = {pathToExistingFile};
string newPath = {pathToNewFile};
FileSystem.FileCopy(oldPath, newPath);Example2
$oldPath = {pathToExistingFile};
$newPath = {pathToNewFile};
FileSystem::FileCopy($oldPath, $newPath);