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
| Type | Name | Description |
|---|---|---|
string | 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
string DirectoryRandomFile(string pathToDirectory)
Get the random file in the directory
Parameters
| Type | Name | Description |
|---|---|---|
string | 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
string DirectorySubItem(string pathToDirectory, string items, string itemNumber, bool sortAlphabetically)
The path to a file/subdirectory in the specified directory
Parameters
| Type | Name | Description |
|---|---|---|
string | pathToDirectory | Path to the directory. |
string | items | Sampling units (“d” - directories, “f” - files, “df” - all together) . |
string | itemNumber | The number of the element. |
bool | 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
void DirectoryDeleteFileByMask(string pathToDirectory, string pattern)
Removes the file by mask
Parameters
| Type | Name | Description |
|---|---|---|
string | pathToDirectory | Path to the directory. |
string | 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
void DirectoryDeleteFile(string pathToFile)
Removes the file
Parameters
| Type | Name | Description |
|---|---|---|
string | pathToFile | Path 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
| Type | Name | Description |
|---|---|---|
string | pathToDirectory | Path to the directory. |
bool | recursive | true if removingrecursively; otherwise, false. |
bool | 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);FileGetLine
Method
string FileGetLine(string path, string numberOfLine, bool removeLine, bool removeEmptyFile)
Gets string from the file
Parameters
| Type | Name | Description |
|---|---|---|
string | path | Path to the source file. |
string | numberOfLine | The number of the line. |
bool | removeLine | true if remove the used line; otherwise, false. |
bool | 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
String[] FileGetLines(string path, string numberOfLine, bool removeLine, bool removeEmptyFile)
Gets strings from the file
Parameters
| Type | Name | Description |
|---|---|---|
string | path | Path to the source file. |
string | numberOfLine | The number of the line. |
bool | removeLine | true if remove the used line; otherwise, false. |
bool | 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
string FileGetLine(string path, string numberOfLine, bool removeLine, string regex, string numberOfMatch, bool removeEmptyFile)
Gets string from the file
Parameters
| Type | Name | Description |
|---|---|---|
string | path | Path to the source file. |
string | numberOfLine | The number of the line. |
bool | removeLine | true if remove the used line; otherwise, false. |
string | regex | Regular expression to parse the line. |
string | numberOfMatch | Number of match after parsing. |
bool | 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
String[] FileGetLines(string path, string numberOfLine, bool removeLine, string regex, string numberOfMatch, bool removeEmptyFile)
Gets strings from the file
Parameters
| Type | Name | Description |
|---|---|---|
string | path | Path to the source file. |
string | numberOfLine | The number of the line. |
bool | removeLine | true if remove the used line; otherwise, false. |
string | regex | Regular expression to parse the line. |
string | numberOfMatch | Number of match after parsing. |
bool | 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
string FileGetBlock(string path, string blockSplitter, string numberOfLine, bool removeBlock, bool removeEmptyFile)
Gets text block from the file
Parameters
| Type | Name | Description |
|---|---|---|
string | path | Path to the source file. |
string | blockSplitter | Delimiter for text in the file. |
string | numberOfLine | The line number after splitting into blocks. |
bool | removeBlock | true if remove the used block; otherwise, false. |
bool | 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
String[] FileGetBlocks(string path, string blockSplitter, string numberOfLine, bool removeBlock, bool removeEmptyFile)
Gets text blocks from the file
Parameters
| Type | Name | Description |
|---|---|---|
string | path | Path to the source file. |
string | blockSplitter | Delimiter for text in the file. |
string | numberOfLine | The line number after splitting into blocks. |
bool | removeBlock | true if remove the used block; otherwise, false. |
bool | 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
void FileAppendString(string path, string text, bool appendNewLine)
Appends line to the end of file
Parameters
| Type | Name | Description |
|---|---|---|
string | path | Path to the file. |
string | text | Text to append. |
bool | 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
string FileCountOfLines(string path)
Get count of lines in the file
Parameters
| Type | Name | Description |
|---|---|---|
string | 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
void FileCopy(string oldPath, string newPath)
Copies an existing file
Parameters
| Type | Name | Description |
|---|---|---|
string | oldPath | Path to the existing file. |
string | 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);