Class FS
- Namespace
- SunamoFileSystem
- Assembly
- SunamoFileSystem.dll
File System utility class providing file and directory operations
public class FS
- Inheritance
-
FS
- Inherited Members
- Extension Methods
Fields
DEndsWithReplaceInFile
Default file name pattern for ends-with replacement operations.
public const string DEndsWithReplaceInFile = "SubdomainHelperSimple.cs"
Field Value
DeleteFileMaybeLocked
Action delegate to delete a file that may be locked by another process.
public static Action<string>? DeleteFileMaybeLocked
Field Value
FileUtilWhoIsLocking
Function to determine which processes are locking a file.
public static Func<string, bool, List<Process>>? FileUtilWhoIsLocking
Field Value
FilesWhichSurelyExists
List of files that are confirmed to exist on disk.
public static List<string> FilesWhichSurelyExists
Field Value
InvalidFileNameChars
List of all invalid file name characters including extended Unicode.
public static List<char> InvalidFileNameChars
Field Value
InvalidFileNameCharsString
Field as string because array requires ToArray() every time to construct string
public static string InvalidFileNameCharsString
Field Value
ReplaceIncorrectFor
Replacement string for incorrect file name characters.
public static string ReplaceIncorrectFor
Field Value
invalidCharsForMapPath
List of invalid characters for path mapping operations.
protected static List<char> invalidCharsForMapPath
Field Value
invalidFileNameCharsReadonly
Read-only list of invalid file name characters from the OS.
protected static readonly List<char> invalidFileNameCharsReadonly
Field Value
invalidFileNameCharsWithoutDelimiterOfFolders
Invalid file name characters excluding directory separators.
protected static List<char> invalidFileNameCharsWithoutDelimiterOfFolders
Field Value
invalidFileNameStringsReadonly
Read-only list of invalid file name characters as strings.
protected static readonly List<string> invalidFileNameStringsReadonly
Field Value
invalidPathChars
List of invalid path characters including directory separators.
protected static List<char> invalidPathChars
Field Value
Methods
AbsoluteFromCombinePath(string)
Usage: SunamoFubuCsprojFileHelper.GetProjectsInSlnFile Cant name GetAbsolutePath because The call is ambiguous between the following methods or properties: 'CAChangeContent.ChangeContent0(null,List<string>, Func<string, string, string>)' and 'CAChangeContent.ChangeContent0(null,List<string>, Func<string, string>)'
public static string AbsoluteFromCombinePath(string path)
Parameters
pathstringPath to convert to absolute path
Returns
AddExtensionIfDontHave(string, string)
Adds a file extension if the path does not already have one.
public static string AddExtensionIfDontHave(string file, string ext)
Parameters
Returns
AddUpfoldersToRelativePath(int, string, char)
Prepends parent directory references to a relative path.
public static string AddUpfoldersToRelativePath(int i2, string file, char delimiter)
Parameters
Returns
AllExtensionsInFolders(List<string>, GetExtensionArgs?)
files as .bowerrc return whole
public static List<string> AllExtensionsInFolders(List<string> filesFull, GetExtensionArgs? args = null)
Parameters
filesFullList<string>List of full file paths.
argsGetExtensionArgsArguments controlling the operation behavior.
Returns
AllExtensionsInFolders(SearchOption, params string[])
Gets all unique file extensions found in the specified folders.
public static List<string> AllExtensionsInFolders(SearchOption so, params string[] folders)
Parameters
soSearchOptionThe so parameter.
foldersstring[]The folders parameter.
Returns
AllIncludeIfOnlyLetters(string)
Wraps a search term with wildcards if it contains only letters.
public static string AllIncludeIfOnlyLetters(string extension)
Parameters
extensionstringThe extension parameter.
Returns
BasePath(List<string>, string)
Finds which base path contains the specified path.
public static string? BasePath(List<string> basePaths, string path)
Parameters
Returns
ChangeDirectory(string, string)
Pokud hledáš metodu ReplacePathToFile, je to tato. Sloučeny protože dělali totéž.
public static string ChangeDirectory(string fileName, string changeFolderTo)
Parameters
Returns
ChangeExtension(string, string, bool)
A2 is path of target file
public static string ChangeExtension(string filePath, string newExt, bool physically)
Parameters
Returns
ChangeFilename(string, string, bool)
Changes the file name of a path, optionally renaming the physical file.
public static string ChangeFilename(string filePath, string newFileNameWithoutPath, bool physically)
Parameters
filePathstringThe file path.
newFileNameWithoutPathstringThe newFileNameWithoutPath parameter.
physicallyboolThe physically parameter.
Returns
Combine(params string[])
Cant return with end slash becuase is working also with files Use this than Path.Combine which if argument starts with backslash ignore all arguments before this
public static string Combine(params string[] parts)
Parameters
partsstring[]The path parts to combine.
Returns
CombineDir(params string[])
Combines multiple path segments into a directory path.
public static string CombineDir(params string[] parts)
Parameters
partsstring[]The parts parameter.
Returns
CombineFile(params string[])
Combines multiple path segments into a file path.
public static string CombineFile(params string[] parts)
Parameters
partsstring[]The parts parameter.
Returns
CombineWithoutFirstCharUpper(params string[])
Cant return with end slash becuase is working also with files
public static string CombineWithoutFirstCharUpper(params string[] text)
Parameters
textstring[]The text to process.
Returns
CompareTWithInt<T>(TWithInt<T>, TWithInt<T>)
Compares two TWithInt instances by their count in descending order.
public static int CompareTWithInt<T>(TWithInt<T> first, TWithInt<T> second)
Parameters
Returns
Type Parameters
T
ContainsInvalidFileNameChars(string)
Checks if a string contains invalid file name characters.
public static bool ContainsInvalidFileNameChars(string arg)
Parameters
argstringThe arg parameter.
Returns
ContainsInvalidPathCharForPartOfMapPath(string)
Checks if a path segment contains invalid characters for mapping.
public static bool ContainsInvalidPathCharForPartOfMapPath(string path)
Parameters
pathstringThe file or directory path.
Returns
CopyAllFiles(ILogger, string, string, FileMoveCollisionOption, string?)
A4 contains can use ! for negation
public static void CopyAllFiles(ILogger logger, string path, string to, FileMoveCollisionOption collisionOption, string? contains = null)
Parameters
loggerILoggerLogger instance for diagnostic messages.
pathstringThe file or directory path.
tostringcollisionOptionFileMoveCollisionOptioncontainsstring
CopyAllFilesRecursively(ILogger, string, string, FileMoveCollisionOption, string?)
Copies all files recursively from source to target directory.
public static void CopyAllFilesRecursively(ILogger logger, string path, string to, FileMoveCollisionOption collisionOption, string? contains = null)
Parameters
loggerILoggerLogger instance for diagnostic messages.
pathstringThe source directory path.
tostringThe target directory path.
collisionOptionFileMoveCollisionOptionHow to handle file name collisions.
containsstringOptional filter string; only files containing this text are copied. Prefix with '!' for negation.
CopyAs0KbFiles(string, string)
Copies files as empty 0KB files to the target directory.
public static void CopyAs0KbFiles(string pathDownload, string pathVideos0Kb)
Parameters
CopyAs0KbFilesSubfolders(string, string)
Copies the folder structure as empty 0KB files including subfolders.
public static void CopyAs0KbFilesSubfolders(string pathDownload, string pathVideos0Kb)
Parameters
CopyFile(ILogger, string, string, FileMoveCollisionOption, bool)
Copies a file from source to destination.
public static void CopyFile(ILogger logger, string sourceFilePath, string fileTo2, FileMoveCollisionOption collisionOption, bool terminateProcessIfIsInUsed = false)
Parameters
loggerILoggerLogger instance for diagnostic messages.
sourceFilePathstringThe source file path to copy from.
fileTo2stringThe destination file path to copy to.
collisionOptionFileMoveCollisionOptionHow to handle file name collisions.
terminateProcessIfIsInUsedboolWhether to terminate the process that is locking the file.
CopyFile(ILogger, string, string, bool)
Copy file by ordinal way tady byly 2 metody CopyFile(string, string, bool) jedna text A3 terminateProcessIfIsInUsed, druhá text overwrite Ta druhá jen volala A3 text FileMoveCollisionOption.Overwrite
public static void CopyFile(ILogger logger, string jsFiles, string value, bool terminateProcessIfIsInUsed = false)
Parameters
loggerILoggerLogger instance for diagnostic messages.
jsFilesstringvaluestringThe value to process.
terminateProcessIfIsInUsedboolWhether to terminate the process if the file is in use.
CopyFile(string, string, FileMoveCollisionOption)
Copies a file from source to destination.
public static void CopyFile(string sourceFilePath, string fileTo2, FileMoveCollisionOption collisionOption)
Parameters
sourceFilePathstringThe sourceFilePath parameter.
fileTo2stringThe fileTo2 parameter.
collisionOptionFileMoveCollisionOptionHow to handle collisions.
CopyFilesOfExtensions(string, string, params string[])
Copies files with specified extensions from source to target directory.
public static void CopyFilesOfExtensions(string folderFrom, string folderTo, params string[] extensions)
Parameters
folderFromstringThe folderFrom parameter.
folderTostringThe folderTo parameter.
extensionsstring[]The extensions parameter.
CopyFolder(string, string)
Use CopyAllFilesRecursively instead
public static void CopyFolder(string sourceDir, string targetDir)
Parameters
CopyMoveFilePrepare(ref string, ref string, FileMoveCollisionOption)
Prepares source and target paths for a copy or move operation with collision handling.
public static bool CopyMoveFilePrepare(ref string sourceFilePath, ref string fileTo, FileMoveCollisionOption collisionOption)
Parameters
sourceFilePathstringThe sourceFilePath parameter.
fileTostringThe fileTo parameter.
collisionOptionFileMoveCollisionOptionHow to handle collisions.
Returns
CopyMoveFilesInList(ILogger, List<string>, string, string, List<string>, bool, bool, Dictionary<string, List<string>>, bool)
Všechny soubory které se podaří přesunout vymažu z A1 A1 MUST BE WITH EXTENSION A4 can be null if !A5 In A1 will keep files which doesnt exists in A3 A4 is files from A1 which wasnt founded in A2 A7 is files
public static void CopyMoveFilesInList(ILogger logger, List<string> filesFrom, string folderFrom, string folderTo, List<string> wasntExistsInFrom, bool mustExistsInTarget, bool copy, Dictionary<string, List<string>> files, bool overwrite = true)
Parameters
loggerILoggerLogger instance for diagnostic messages.
filesFromList<string>List of source file paths relative to folderFrom.
folderFromstringSource folder path.
folderTostringTarget folder path.
wasntExistsInFromList<string>List to collect files that did not exist in source.
mustExistsInTargetboolWhether files must exist in target.
copyboolWhether to copy (true) or move (false).
filesDictionary<string, List<string>>Dictionary mapping file categories to their paths.
overwriteboolWhether to overwrite existing files.
CopyMoveFilesInListSimple(ILogger, List<string>, string, string, bool, bool)
Simplified version of CopyMoveFilesInList for basic copy/move operations.
public static void CopyMoveFilesInListSimple(ILogger logger, List<string> files, string basePathCjHtml1, string basePathCjHtml2, bool copy, bool overwrite = true)
Parameters
loggerILoggerLogger instance for diagnostic messages.
filesList<string>The files parameter.
basePathCjHtml1stringThe basePathCjHtml1 parameter.
basePathCjHtml2stringThe basePathCjHtml2 parameter.
copyboolThe copy parameter.
overwriteboolWhether to overwrite existing files.
CopyMoveFromMultiLocationIntoOne(ILogger, List<string>, string, string)
A1 must be with extensions!
public static void CopyMoveFromMultiLocationIntoOne(ILogger logger, List<string> files, string folderFrom, string folderTo)
Parameters
loggerILoggerLogger instance for diagnostic messages.
filesList<string>folderFromstringfolderTostring
CopyStream(Stream, Stream)
Copies data from one stream to another.
public static void CopyStream(Stream input, Stream output)
Parameters
CopyTo(string, string, FileMoveCollisionOption)
Copy file A1 into A2
public static void CopyTo(string value, string targetDirectory, FileMoveCollisionOption collisionOption)
Parameters
valuestringtargetDirectorystringcollisionOptionFileMoveCollisionOptionHow to handle file name collisions.
CreateDirectory(string)
All occurences Path's method in sunamo replaced
public static void CreateDirectory(string value)
Parameters
valuestringThe value to process.
CreateDirectory(string, DirectoryCreateCollisionOption, SerieStyleFS, bool)
Creates a directory with collision handling options.
public static string CreateDirectory(string value, DirectoryCreateCollisionOption whenExists, SerieStyleFS serieStyle, bool reallyCreate)
Parameters
valuestringThe value to process.
whenExistsDirectoryCreateCollisionOptionThe whenExists parameter.
serieStyleSerieStyleFSThe serieStyle parameter.
reallyCreateboolThe reallyCreate parameter.
Returns
CreateDirectoryIfNotExists(string)
Creates a directory if it does not already exist.
public static void CreateDirectoryIfNotExists(string path)
Parameters
pathstringThe file or directory path.
CreateFileIfDoesntExists(string)
Creates an empty file if it does not already exist.
public static void CreateFileIfDoesntExists(string path)
Parameters
pathstringThe file or directory path.
CreateFileWithTemplateContent(string, string, string, string)
Creates a file with content based on a template with placeholder replacement.
public static void CreateFileWithTemplateContent(string folder, string files, string ext, string templateFromContent)
Parameters
folderstringThe directory path.
filesstringThe files parameter.
extstringThe ext parameter.
templateFromContentstringThe templateFromContent parameter.
CreateFoldersPsysicallyUnlessThere(string)
Creates all parent folders of the specified path if they don't exist
public static void CreateFoldersPsysicallyUnlessThere(string path)
Parameters
pathstringThe folder path to create
CreateInOtherLocationSameFolderStructure(string, string)
Recreates the folder structure from one location in another.
public static void CreateInOtherLocationSameFolderStructure(string from, string to)
Parameters
CreateNewFolderPathWithEndingNextTo(string, string)
Creates a new folder path adjacent to the specified path.
public static string CreateNewFolderPathWithEndingNextTo(string folder, string ending)
Parameters
Returns
CreateUpfoldersPsysicallyUnlessThere(string)
Creates all parent folders of the specified path if they don't exist
public static void CreateUpfoldersPsysicallyUnlessThere(string path)
Parameters
pathstringThe file or folder path
DeleteAllEmptyDirectories(string, params string[])
Zjistí všechny složky rekurzivně z A1 a prvně maže samozřejmě ty, které mají více tokenů
public static void DeleteAllEmptyDirectories(string value, params string[] excludePatterns)
Parameters
valuestringThe directory path to process
excludePatternsstring[]Paths containing these strings will not be deleted
DeleteAllRecursively(string, bool)
Deletes all files and optionally directories recursively.
public static void DeleteAllRecursively(string path, bool rootDirectoryToo = false)
Parameters
pathstringThe file or directory path to delete contents from.
rootDirectoryTooboolWhether to also delete the root directory itself.
DeleteAllRecursivelyAndThenDirectory(string)
Vyhazuje výjimky, takže musíš volat value try-catch bloku
public static void DeleteAllRecursivelyAndThenDirectory(string path)
Parameters
pathstringThe directory path to delete
DeleteDuplicatedImages(List<string>)
Unit tests = OK
public static void DeleteDuplicatedImages(List<string> files)
Parameters
DeleteEmptyFiles(string, SearchOption)
Deletes all empty (0-byte) files in the specified folder.
public static Task DeleteEmptyFiles(string folder, SearchOption so)
Parameters
folderstringThe directory path to search in.
soSearchOptionSpecifies whether to search the current directory or all subdirectories.
Returns
DeleteFile(string)
Deletes a file from disk, attempting to handle locked files.
public static void DeleteFile(string filePath)
Parameters
filePathstringThe file path.
DeleteFileIfExists(string)
Odstraňuje samozřejmě ve výjimce
public static void DeleteFileIfExists(string path)
Parameters
pathstring
DeleteFilesWithSameContent(List<string>)
Working fine, verified by Unit tests
public static void DeleteFilesWithSameContent(List<string> files)
Parameters
DeleteFilesWithSameContentBytes(List<string>)
Unit tests = OK
public static void DeleteFilesWithSameContentBytes(List<string> files)
Parameters
DeleteFilesWithSameContentWorking<TContent, ColType>(List<string>, Func<string, TContent>)
Deletes files with same content by comparing their content using the provided read function Currently kept as sync because Func only has Invoke, cannot use async benefits
public static void DeleteFilesWithSameContentWorking<TContent, ColType>(List<string> files, Func<string, TContent> readFunc) where TContent : notnull
Parameters
filesList<string>List of file paths to check for duplicates
readFuncFunc<string, TContent>Function to read file content
Type Parameters
TContentThe type of content to compare
ColTypeThe collection element type
DeleteFoldersWhichNotContains(string, string, IList<string>)
Deletes folders that do not contain files matching specified patterns.
public static void DeleteFoldersWhichNotContains(string value, string folder, IList<string> excludedContainingTexts)
Parameters
valuestringThe value to process.
folderstringThe directory path.
excludedContainingTextsIList<string>The excludedContainingTexts parameter.
DeleteSerieDirectoryOrCreateNew(string)
Delete whole folder A1. If fail, only "1" subdir Use in RepairBlogContent but sample data is NA Deleting old folder hiearchy and create new
public static int DeleteSerieDirectoryOrCreateNew(string repairedBlogPostsFolder)
Parameters
repairedBlogPostsFolderstring
Returns
DeleteWrongCharsInDirectoryName(string)
Removes invalid characters from a directory name.
public static string DeleteWrongCharsInDirectoryName(string path)
Parameters
pathstringThe file or directory path.
Returns
DeleteWrongCharsInFileName(string, bool)
Removes invalid characters from a file name.
public static string DeleteWrongCharsInFileName(string path, bool isPath)
Parameters
Returns
DetectPathDelimiter(string)
Detects the path delimiter used in a path string.
public static Tuple<bool, bool> DetectPathDelimiter(string path)
Parameters
pathstringThe file or directory path.
Returns
DetectPathDelimiterChar(string)
Detects the path delimiter character used in a path string.
public static char DetectPathDelimiterChar(string path)
Parameters
pathstringThe file or directory path.
Returns
DirectoriesWithToken(string, AscDesc)
Gets directories sorted by a numeric token in their path.
public static List<TWithInt<string>> DirectoriesWithToken(string value, AscDesc sortOrder)
Parameters
Returns
DirectoryExistsAndIsNotEmpty(string)
Checks if a directory exists and contains files or subdirectories.
public static bool DirectoryExistsAndIsNotEmpty(string value)
Parameters
valuestringThe value to process.
Returns
DirectoryListing(string, string, SearchOption)
Lists files in a directory matching a pattern.
public static List<string> DirectoryListing(string path, string mask, SearchOption so)
Parameters
pathstringThe file or directory path.
maskstringThe mask parameter.
soSearchOptionThe so parameter.
Returns
ExistsDirectory(string)
Determines whether the specified directory exists on disk.
public static bool ExistsDirectory(string path)
Parameters
pathstringThe file or directory path.
Returns
ExistsDirectory(string, bool)
Determines whether the specified directory exists on disk.
public static bool ExistsDirectory(string directoryPath, bool isFalseIfContainsNoFile = false)
Parameters
directoryPathstringThe directory path to check.
isFalseIfContainsNoFileboolWhether to return false if the directory exists but contains no files.
Returns
ExistsDirectoryNull(string)
For empty or whitespace return false.
public static bool? ExistsDirectoryNull(string directoryPath)
Parameters
directoryPathstring
Returns
- bool?
ExistsDirectoryNull(string, bool)
Returns null if the directory does not exist.
public static bool? ExistsDirectoryNull(string directoryPath, bool isFalseIfContainsNoFile = false)
Parameters
directoryPathstringThe directory path to check.
isFalseIfContainsNoFileboolWhether to return false if the directory exists but contains no files.
Returns
- bool?
ExistsDirectoryWorker(string, bool)
Convert to UNC path
public static bool ExistsDirectoryWorker(string directoryPath, bool isFalseIfContainsNoFile = false)
Parameters
directoryPathstringThe directory path to check
isFalseIfContainsNoFileboolReturn false if directory contains no files
Returns
ExistsFile(string)
Determines whether the specified file exists on disk.
public static bool ExistsFile(string path)
Parameters
pathstringThe file or directory path.
Returns
ExistsFile(string, bool)
Dont check for size Into A2 is good put true - when storage was fulled, all new files will be written with zero size. But then failing because HtmlNode as null - empty string as input But when file is big, like backup of DB, its better false.. Then will be avoid reading whole file to determining their size and totally blocking HW resources on VPS A2 must be false otherwise read file twice Change falseIfSizeZeroOrEmpty = false. Its extremely resource intensive
public static Task<bool> ExistsFile(string selectedFile, bool falseIfSizeZeroOrEmpty)
Parameters
selectedFilestringThe file path to check for existence.
falseIfSizeZeroOrEmptyboolWhether to return false if the file exists but has zero size or is empty.
Returns
ExpandEnvironmentVariables(EnvironmentVariables)
Expands a known environment variable to its value.
public static string ExpandEnvironmentVariables(EnvironmentVariables environmentVariable)
Parameters
environmentVariableEnvironmentVariablesThe environmentVariable parameter.
Returns
FileToDirectory(ref string)
Converts a file path to its parent directory path.
public static void FileToDirectory(ref string dir)
Parameters
dirstringThe dir parameter.
FilesWhichContainsAll(object, string, params string[])
Finds files matching a pattern that contain all required contents.
public static List<string> FilesWhichContainsAll(object sunamo, string searchPattern, params string[] requiredContents)
Parameters
sunamoobjectThe sunamo parameter.
searchPatternstringThe searchPattern parameter.
requiredContentsstring[]The requiredContents parameter.
Returns
FilesWithSameName(string, string, SearchOption)
Usage: FileWasntFoundInDirectory Vrátí cestu a název souboru text ext
public static string FilesWithSameName(string folder, string searchPattern, SearchOption searchOption)
Parameters
folderstringsearchPatternstringsearchOptionSearchOption
Returns
FilterInRootAndInSubFolder(string, List<string>)
Separates files into root-level and subfolder groups.
public static List<string> FilterInRootAndInSubFolder(string rootFolder, List<string> files)
Parameters
Returns
FirstCharUpper(string)
Converts the first character of a string to uppercase
public static string FirstCharUpper(string text)
Parameters
textstringThe text to process
Returns
- string
String with first character in uppercase
FirstCharUpper(string, bool)
Converts the first character of a path to uppercase.
public static string? FirstCharUpper(string text, bool only = false)
Parameters
textstringThe text to process.
onlyboolWhether to only uppercase the first character and lowercase the rest.
Returns
FirstCharUpper(ref string)
Converts the first character of a path to uppercase.
public static string FirstCharUpper(ref string result)
Parameters
resultstringThe result parameter.
Returns
FoldersWithSubfolder(string, string)
Finds all folders that contain a specific subfolder.
public static List<string> FoldersWithSubfolder(string solutionFolder, string folderName)
Parameters
Returns
GetAbsolutePath(string, string)
Working - see unit tests if A1 not ending with , GetDirectoryName
public static string GetAbsolutePath(string dir, string relativePath)
Parameters
Returns
GetAbsolutePath2(string, string)
Not working - see unit tests
public static string GetAbsolutePath2(string relativePath, string dir)
Parameters
Returns
GetActualDateTime()
Returns the current date and time as a file-safe string.
public static string GetActualDateTime()
Returns
GetDictionaryByExtension(string, string, SearchOption)
Both filenames and extension convert to lowercase Filename is without extension
public static Dictionary<string, List<string>> GetDictionaryByExtension(string folder, string mask, SearchOption searchOption)
Parameters
folderstringmaskstringsearchOptionSearchOption
Returns
GetDictionaryByFileNameWithExtension(List<string>)
In key are just filename, in value full path to all files
public static Dictionary<string, List<string>> GetDictionaryByFileNameWithExtension(List<string> files)
Parameters
Returns
GetDirectoryName(string)
Usage: Exceptions.FileWasntFoundInDirectory
public static string GetDirectoryName(string path)
Parameters
pathstringThe file or directory path.
Returns
GetDirectoryNameIfIsFile(string)
Returns the directory name if the path points to a file, otherwise returns the path.
public static string GetDirectoryNameIfIsFile(string path)
Parameters
pathstringThe file or directory path.
Returns
GetExtension(string, GetExtensionArgs?)
.babelrc etc. return as is. but files which not contains only alphanumeric will be returned when A3 (and A2 is then ignored) ALL EXT. HAVE TO BE ALWAYS LOWER Return in lowercase
public static string GetExtension(string value, GetExtensionArgs? args = null)
Parameters
valuestringThe file path to extract extension from
argsGetExtensionArgsOptional arguments for extension extraction
Returns
GetFileInStartupPath(string)
Jen kvuli starým aplikacím, at furt nenahrazuji.
public static string GetFileInStartupPath(string value)
Parameters
valuestringThe value to process.
Returns
GetFileName(string)
Gets the file name from a full path.
public static string GetFileName(string filePath)
Parameters
filePathstringThe file path.
Returns
GetFileNameWithoutExtension(string)
Gets the file name from a path without the extension.
public static string GetFileNameWithoutExtension(string text)
Parameters
textstringThe text to process.
Returns
GetFileNameWithoutExtensionAndExtension(string, out string, out string)
A1 může obsahovat celou cestu, vrátí jen název sobuoru bez připony a příponu
public static void GetFileNameWithoutExtensionAndExtension(string filePath, out string file, out string ext)
Parameters
GetFileNameWithoutExtensionLower(string)
Pokud by byla cesta zakončená backslashem, vrátila by metoda Path.GetFileName prázdný řetězec.
public static string GetFileNameWithoutExtensionLower(string text)
Parameters
textstringThe file path to process
Returns
GetFileNameWithoutExtensionNoAc<StorageFile>(StorageFile)
Problémová metoda Píše že nemůže najít SunamoValues, přitom value nugetech je
public static StorageFile GetFileNameWithoutExtensionNoAc<StorageFile>(StorageFile text)
Parameters
textStorageFileThe text to process.
Returns
- StorageFile
Type Parameters
StorageFile
GetFileNameWithoutExtensions(string)
Remove all extensions, not only one
public static string GetFileNameWithoutExtensions(string path)
Parameters
pathstringFile path to process
Returns
GetFileNameWithoutOneExtension(string)
Gets the file name by removing the last path segment.
public static string GetFileNameWithoutOneExtension(string path)
Parameters
pathstringThe file or directory path.
Returns
GetFileNamesWoExtension(List<string>)
Gets file names without extensions from a list of paths.
public static List<string> GetFileNamesWoExtension(List<string> jpgcka)
Parameters
Returns
GetFileSerie(string, SerieStyleFS)
Retun null if serie is not defined
public static string? GetFileSerie(string fnwoe, SerieStyleFS ss)
Parameters
fnwoestringssSerieStyleFS
Returns
GetFileSeries(string, string, string)
Get number higher by one from the number filenames with highest value (as 3.txt)
public static string GetFileSeries(string folder, string fileName, string ext)
Parameters
Returns
GetFileSize(string)
Gets the size of a file in bytes.
public static long GetFileSize(string filePath)
Parameters
filePathstringThe file path.
Returns
GetFiles(string, bool)
Gets files from a directory, optionally including subdirectories.
public static List<string> GetFiles(string folderPath, bool recursive)
Parameters
Returns
GetFolderSize(DirectoryInfo)
Calculates the total size of all files in a folder.
public static long GetFolderSize(DirectoryInfo directoryInfo)
Parameters
directoryInfoDirectoryInfoThe directoryInfo parameter.
Returns
GetFolderSize(string)
Calculates the total size of all files in a folder.
public static long GetFolderSize(string path)
Parameters
pathstringThe file or directory path.
Returns
GetFullPath(string)
Gets the fully qualified path for a relative path.
public static string GetFullPath(string path)
Parameters
pathstringThe file or directory path.
Returns
GetNameWithoutSeries(string, bool)
Do A1 se dává buď celá cesta ke souboru, nebo jen jeho název(může být i včetně neomezeně přípon) A2 říká, zda se má vrátit plná cesta ke souboru A1, upraví se pouze samotný název souboru Works for brackets, not dash
public static string GetNameWithoutSeries(string path, bool a1IsWithPath)
Parameters
Returns
GetNameWithoutSeries(string, bool, out bool, SerieStyleFS)
Extracts the base name from a file name by removing series suffixes.
public static string GetNameWithoutSeries(string path, bool a1IsWithPath, out bool hasSerie, SerieStyleFS serieStyle)
Parameters
pathstringThe file or directory path.
a1IsWithPathboolThe a1IsWithPath parameter.
hasSerieboolThe hasSerie parameter.
serieStyleSerieStyleFSThe serieStyle parameter.
Returns
GetNameWithoutSeries(string, bool, out bool, SerieStyleFS, out int)
Vrací vždy text příponou Do A1 se dává buď celá cesta ke souboru, nebo jen jeho název(může být i včetně neomezeně přípon) A2 říká, zda se má vrátit plná cesta ke souboru A1, upraví se pouze samotný název souboru When file has unknown extension, return SE Default for A4 was bracket
public static string GetNameWithoutSeries(string path, bool a1IsWithPath, out bool hasSerie, SerieStyleFS serieStyle, out int serie)
Parameters
pathstringThe file path to extract the name from.
a1IsWithPathboolWhether the path includes the directory path.
hasSerieboolOutput flag indicating whether a series suffix was found.
serieStyleSerieStyleFSThe serie naming style to use.
serieintOutput value of the series number found, or -1 if none.
Returns
GetNameWithoutSeriesNoOut(string, bool, SerieStyleFS)
1 = filename without serie 2 = has serie
public static (string, bool) GetNameWithoutSeriesNoOut(string path, bool a1IsWithPath, SerieStyleFS serieStyle)
Parameters
pathstringa1IsWithPathboolWhether the first argument includes a path.
serieStyleSerieStyleFS
Returns
GetNormalizedExtension(string)
Gets the normalized extension from a file path.
public static string GetNormalizedExtension(string filename)
Parameters
filenamestringThe filename parameter.
Returns
GetPathAndFileName(string, out string, out string)
Usage: Exceptions.FileWasntFoundInDirectory
public static void GetPathAndFileName(string filePath, out string path, out string file)
Parameters
GetPathAndFileName(string, out string, out string, out string)
Vrátí cestu a název souboru text ext a ext
public static void GetPathAndFileName(string filePath, out string path, out string file, out string ext)
Parameters
GetPathAndFileNameWithoutExtension(string, out string, out string, out string)
Vrátí cestu a název souboru bez ext a ext All returned is normal case
public static void GetPathAndFileNameWithoutExtension(string filePath, out string path, out string file, out string ext)
Parameters
GetSizeIn(long, ComputerSizeUnits, ComputerSizeUnits)
Converts a file size value between different computer size units.
public static long GetSizeIn(long value, ComputerSizeUnits fromUnit, ComputerSizeUnits to)
Parameters
valuelongThe value to process.
fromUnitComputerSizeUnitsThe fromUnit parameter.
toComputerSizeUnitsThe to parameter.
Returns
GetSizeInAutoString(double)
Returns a human-readable file size string with automatic unit selection.
public static string GetSizeInAutoString(double size)
Parameters
sizedoubleThe size parameter.
Returns
GetSizeInAutoString(double, ComputerSizeUnits)
A1 is input unit, not output
public static string GetSizeInAutoString(double value, ComputerSizeUnits fromUnit)
Parameters
valuedoublefromUnitComputerSizeUnitsThe source unit of measurement.
Returns
GetSizeInAutoString(long, ComputerSizeUnits)
Returns a human-readable file size string with automatic unit selection.
public static string GetSizeInAutoString(long value, ComputerSizeUnits fromUnit)
Parameters
valuelongThe value to process.
fromUnitComputerSizeUnitsThe fromUnit parameter.
Returns
GetTempFilePath()
path + file
public static string GetTempFilePath()
Returns
GetTokens(string)
Splits a path into its component tokens.
public static List<string> GetTokens(string relativePath)
Parameters
relativePathstringThe relativePath parameter.
Returns
GetUpFolderWhichContainsExtension(string, string)
Traverses up the directory tree to find a folder containing files with the specified extension.
public static string? GetUpFolderWhichContainsExtension(string path, string fileExt)
Parameters
Returns
GroupFilesByName(List<string>)
Groups file paths by their file name.
public static Dictionary<string, List<string>> GroupFilesByName(List<string> filesInSubfolders)
Parameters
Returns
HasAnyFoldersOrFiles(string)
Determines if a folder contains any files or subdirectories.
public static bool HasAnyFoldersOrFiles(string folder)
Parameters
folderstringThe directory path.
Returns
InsertBetweenFileNameAndExtension(string, string)
Inserts text between the file name and its extension.
public static string InsertBetweenFileNameAndExtension(string orig, string whatInsert)
Parameters
Returns
InsertBetweenFileNameAndExtensionRemovePath(string, string)
Vratí bez cesty, pouze název souboru Earlier name InsertBetweenFileNameAndExtension2
public static string InsertBetweenFileNameAndExtensionRemovePath(string orig, string whatInsert)
Parameters
Returns
InsertBetweenFileNameAndPath(string, string, string)
Toto vkládá jako novou složku.
either A1 or A2 can be null
When A2 is null, will get from file path A1
public static string InsertBetweenFileNameAndPath(string folder, string parentFolder, string insert)
Parameters
Returns
IsAbsolutePath(string)
Determines whether the specified path is an absolute path.
public static bool IsAbsolutePath(string path)
Parameters
pathstringThe file or directory path.
Returns
IsAllInSameFolder(List<string>)
Determines if all paths in the list are in the same folder.
public static bool IsAllInSameFolder(List<string> paths)
Parameters
Returns
IsCountOfFilesMoreThan(string, string, int)
Checks if the number of files matching a pattern exceeds a threshold.
public static bool IsCountOfFilesMoreThan(string folderPath, string searchPattern, int getNullIfThereIsMoreThanXFiles)
Parameters
folderPathstringThe folderPath parameter.
searchPatternstringThe searchPattern parameter.
getNullIfThereIsMoreThanXFilesintThe getNullIfThereIsMoreThanXFiles parameter.
Returns
IsExtension(string)
Determines whether the specified string is a valid file extension.
public static bool IsExtension(string result)
Parameters
resultstringThe result parameter.
Returns
IsFileOlderThanXHours(string, int, bool)
Determines whether a file is older than the specified number of hours.
public static bool IsFileOlderThanXHours(string path, int hours, bool mustFileExists = false)
Parameters
pathstringThe file path to check.
hoursintThe threshold number of hours.
mustFileExistsboolWhether to throw an exception if the file does not exist.
Returns
IsWindowsPathFormat(string)
Usage: Exceptions.IsNotWindowsPathFormat
public static bool IsWindowsPathFormat(string argValue)
Parameters
argValuestring
Returns
KeepOnlyWhichIsNotInFiles(List<string>, List<string>)
Filters a list to keep only items not found in the specified files.
public static Task<List<string>> KeepOnlyWhichIsNotInFiles(List<string> opts, List<string> paths)
Parameters
optsList<string>The list of options to filter.
pathsList<string>The list of file paths to compare against.
Returns
LastModified(string)
Gets the last modified date and time of a file.
public static DateTime LastModified(string rel)
Parameters
relstringThe rel parameter.
Returns
MakeFromLastPartFile(string, string)
Creates a file from the last part of a path with the specified extension.
public static string MakeFromLastPartFile(string fullPath, string ext)
Parameters
Returns
MakeUncLongPath(string)
Converts a path to UNC long path format to support paths longer than 260 characters.
public static string MakeUncLongPath(string path)
Parameters
pathstringThe file or directory path.
Returns
MakeUncLongPath(ref string)
Converts a path to UNC long path format to support paths longer than 260 characters.
public static string MakeUncLongPath(ref string path)
Parameters
pathstringThe file or directory path.
Returns
MascFromExtension(string)
Creates a wildcard search mask from a file extension.
public static string MascFromExtension(string ext2 = "*")
Parameters
ext2stringThe file extension or wildcard pattern to create a mask from.
Returns
MaskFromExtensions(List<string>)
Creates a wildcard search mask from a list of file extensions.
public static string MaskFromExtensions(List<string> allExtensions)
Parameters
Returns
ModifiedinUnix(string)
Gets the last modified time of a file as a Unix timestamp.
public static long ModifiedinUnix(string filePath)
Parameters
filePathstringThe file path.
Returns
MoveAllFilesRecursively(ILogger, string, string, FileMoveCollisionOption, string?)
Moves all files recursively from source to target directory.
[Obsolete("Use MoveDirectoryNoRecursive instead")]
public static void MoveAllFilesRecursively(ILogger logger, string sourcePath, string targetPath, FileMoveCollisionOption collisionOption, string? contains = null)
Parameters
loggerILoggerLogger instance for diagnostic messages.
sourcePathstringThe source directory path.
targetPathstringThe target directory path.
collisionOptionFileMoveCollisionOptionHow to handle file name collisions.
containsstringOptional filter string; only files containing this text are moved. Prefix with '!' for negation.
MoveAllRecursivelyAndThenDirectory(ILogger, string, string, FileMoveCollisionOption)
Moves all files recursively and then deletes the directory structure Throws exceptions, so must be called from try-catch block
public static void MoveAllRecursivelyAndThenDirectory(ILogger logger, string sourcePath, string targetPath, FileMoveCollisionOption collisionOption)
Parameters
loggerILoggerLogger instance
sourcePathstringSource directory path
targetPathstringTarget directory path (root of target folder)
collisionOptionFileMoveCollisionOptionFile collision handling option
MoveDirectoryNoRecursive(ILogger, string, string, DirectoryMoveCollisionOption, FileMoveCollisionOption)
A1 i A2 musí končit backslashem Může vyhodit výjimku takže je nutné to odchytávat ve volající metodě If destination folder exists, source folder without files keep Return message if success, or null A5 false
public static string MoveDirectoryNoRecursive(ILogger logger, string from, string to, DirectoryMoveCollisionOption directoryMoveCollisionOption, FileMoveCollisionOption fileMoveCollisionOption)
Parameters
loggerILoggerLogger instance
fromstringSource directory path
tostringDestination directory path
directoryMoveCollisionOptionDirectoryMoveCollisionOptionDirectory collision handling option
fileMoveCollisionOptionFileMoveCollisionOptionFile collision handling option
Returns
MoveDirectoryNoRecursive(string, string, DirectoryMoveCollisionOption, object)
Moves a directory without recursion.
public static void MoveDirectoryNoRecursive(string sourcePath, string targetPath, DirectoryMoveCollisionOption directoryMoveCollisionOption, object fileMoveCollisionOption)
Parameters
sourcePathstringThe sourcePath parameter.
targetPathstringThe targetPath parameter.
directoryMoveCollisionOptionDirectoryMoveCollisionOptionThe directoryMoveCollisionOption parameter.
fileMoveCollisionOptionobjectThe fileMoveCollisionOption parameter.
MoveFile(ILogger, string, string, FileMoveCollisionOption)
A2 is path of target file
public static void MoveFile(ILogger logger, string sourceFilePath, string fileTo, FileMoveCollisionOption collisionOption)
Parameters
loggerILoggerLogger instance for diagnostic messages.
sourceFilePathstringThe sourceFilePath parameter.
fileTostringcollisionOptionFileMoveCollisionOption
MoveSubfoldersToFolder(ILogger, List<string>, string, string, FileMoveCollisionOption)
Moves specified subfolders from one location to another.
public static void MoveSubfoldersToFolder(ILogger logger, List<string> subfolderNames, string from, string to, FileMoveCollisionOption fo)
Parameters
loggerILoggerLogger instance for diagnostic messages.
subfolderNamesList<string>The subfolderNames parameter.
fromstringThe from parameter.
tostringThe to parameter.
foFileMoveCollisionOptionThe fo parameter.
NormalizeExtension(string)
convert to lowercase and remove first dot - to už asi neplatí. Use NormalizeExtension2 for that
public static string NormalizeExtension(string extension)
Parameters
extensionstring
Returns
NormalizeExtension2(string)
Normalizes a file extension by converting to lowercase and removing the leading dot.
public static string NormalizeExtension2(string extension)
Parameters
extensionstringThe file extension to normalize.
Returns
NormalizeExtensions(List<string>)
convert to lowercase and remove first dot
public static void NormalizeExtensions(List<string> extension)
Parameters
NumberByDateModified(ILogger, string, string, SearchOption)
Numbers files by their modification date.
public static void NumberByDateModified(ILogger logger, string folder, string searchPattern, SearchOption so)
Parameters
loggerILoggerLogger instance for diagnostic messages.
folderstringThe directory path.
searchPatternstringThe searchPattern parameter.
soSearchOptionThe so parameter.
OnlyExtensionToLowerWithPath(string)
Gets the lowercase extension of a single file path.
public static string OnlyExtensionToLowerWithPath(string data)
Parameters
datastringThe data parameter.
Returns
OnlyExtensions(List<string>)
Extracts only the extensions from a list of file paths.
public static List<string> OnlyExtensions(List<string> paths)
Parameters
Returns
OnlyExtensionsToLower(List<string>, GetExtensionArgs?)
Extracts extensions from file paths and converts them to lowercase.
public static List<string> OnlyExtensionsToLower(List<string> paths, GetExtensionArgs? args = null)
Parameters
pathsList<string>The list of file paths to extract extensions from.
argsGetExtensionArgsOptional arguments for controlling extension extraction behavior.
Returns
OnlyExtensionsToLowerWithPath(List<string>)
Extracts lowercase extensions from file paths, preserving the path context.
public static List<string> OnlyExtensionsToLowerWithPath(List<string> paths)
Parameters
Returns
OnlyNames(List<string>)
Replaces full paths with just file names in the list.
public static void OnlyNames(List<string> subfolders)
Parameters
OnlyNamesNoDirectEdit(List<string>)
No direct edit Returns with extension POZOR: Na rozdíl od stejné metody value sunamo tato metoda vrací úplně nové pole a nemodifikuje A1
public static List<string> OnlyNamesNoDirectEdit(List<string> files2)
Parameters
Returns
OnlyNamesNoDirectEdit(string, List<string>)
No direct edit
public static List<string> OnlyNamesNoDirectEdit(string appendToStart, List<string> fullPaths)
Parameters
Returns
OnlyNamesNoDirectEdit(string[])
No direct edit
public static List<string> OnlyNamesNoDirectEdit(string[] files2)
Parameters
files2string[]
Returns
OnlyNamesWithoutExtension(List<string>)
Direct edit
public static List<string> OnlyNamesWithoutExtension(List<string> path)
Parameters
Returns
OnlyNamesWithoutExtension(string, List<string>)
Replaces full paths with file names without extensions.
public static List<string> OnlyNamesWithoutExtension(string appendToStart, List<string> fullPaths)
Parameters
Returns
OnlyNamesWithoutExtensionCopy(List<string>)
Returns a new list containing only file names without extensions.
public static List<string> OnlyNamesWithoutExtensionCopy(List<string> paths)
Parameters
Returns
OrderByNaturalNumberSerie(List<string>)
Normally: 11,12,1,2,... This: 1,2,...,11,12 non direct edit working with full paths or just filenames
public static List<string> OrderByNaturalNumberSerie(List<string> list)
Parameters
Returns
PathSpecialAndLevel(string, string, int)
Constructs a path from base and relative segments up to a specified depth level.
public static string PathSpecialAndLevel(string basePath, string relativePath, int value)
Parameters
basePathstringThe basePath parameter.
relativePathstringThe relativePath parameter.
valueintThe value to process.
Returns
PathWithoutExtension(string)
Returns the full path without the file extension.
public static string PathWithoutExtension(string path)
Parameters
pathstringThe file or directory path.
Returns
PlaceInFolder(string, string)
Places a file in a folder by combining the target folder path with the file's parent folder name and file name
public static string PlaceInFolder(string sourcePath, string targetFolder)
Parameters
Returns
- string
Combined path: targetFolder/parentFolderName/fileName
Postfix(string, string)
Appends a postfix to a file name before the extension.
public static string Postfix(string aPath, string text)
Parameters
Returns
ReadAllText(string)
Reads all text content from a file.
public static Task<string> ReadAllText(string path)
Parameters
pathstringThe file path to read from.
Returns
RelativeToAbsolutePath(string, string)
count:\repos\EOM-7\Marvin\Module.VBtO\Clients\src\apps\vbto\src\pages\Administration\Administration.test.tsx ../../../../../../../node_modules/@mui/material/Switch/Switch => count:\repos\EOM-7\Marvin\Module.VBtO\Clients\node_modules@mui\material\Switch\Switch => OK
public static string RelativeToAbsolutePath(string fullPathToSecondFile, string relativePath)
Parameters
Returns
RemoveDiacriticInFileContents(string, string)
Removes diacritic marks from file contents in the specified folder.
public static Task RemoveDiacriticInFileContents(string folder, string mask)
Parameters
Returns
RemoveDiacriticInFileSystemEntryNames(string)
Kromě jmen také zbavuje diakritiky složky.
public static void RemoveDiacriticInFileSystemEntryNames(string folder)
Parameters
folderstring
RemoveFile(string)
Removes a file from disk.
public static string RemoveFile(string fullPathCsproj)
Parameters
fullPathCsprojstringThe fullPathCsproj parameter.
Returns
RemoveSerieUnderscore(string)
Removes the underscore-style series suffix from a file name.
public static string RemoveSerieUnderscore(string data)
Parameters
datastringThe data parameter.
Returns
RenameDirectory(ILogger, string, string, DirectoryMoveCollisionOption, FileMoveCollisionOption)
Může výhodit výjimku, proto je nutné používat value try-catch bloku Vrátí řetězec se zprávou kterou vypsat nebo null
public static string RenameDirectory(ILogger logger, string path, string newname, DirectoryMoveCollisionOption directoryCollisionOption, FileMoveCollisionOption fileCollisionOption)
Parameters
loggerILoggerLogger instance for diagnostic messages.
pathstringThe directory path to rename.
newnamestringThe new directory name.
directoryCollisionOptionDirectoryMoveCollisionOptionHow to handle directory name collisions.
fileCollisionOptionFileMoveCollisionOptionHow to handle file name collisions during the move.
Returns
RenameFile(ILogger, string, string, FileMoveCollisionOption)
A1,2 = with ext Physically rename file, this method is different from ChangeFilename in FileMoveCollisionOption A3 which can control advanced collision solution
public static void RenameFile(ILogger logger, string oldPath, string newFileNameWithoutPath, FileMoveCollisionOption collisionOption)
Parameters
loggerILoggerLogger instance for diagnostic messages.
oldPathstringnewFileNameWithoutPathstringcollisionOptionFileMoveCollisionOption
RenameNumberedSerieFiles(ILogger, List<string>, List<string>, int, string)
A1 is new names of files without extension. Can use LinearHelper
public static void RenameNumberedSerieFiles(ILogger logger, List<string> data, List<string> files, int startFrom, string ext)
Parameters
loggerILoggerLogger instance
dataList<string>New names of files without extension
filesList<string>List of file paths to rename
startFromintStarting index for renaming
extstringFile extension
RenameNumberedSerieFiles(ILogger, List<string>, string, int, string)
RenameNumberedSerieFiles - Rename files by linear names - 0,1,...,x
public static void RenameNumberedSerieFiles(ILogger logger, List<string> data, string path, int startFrom, string ext)
Parameters
loggerILoggerLogger instance
dataList<string>New names of files without extension
pathstringDirectory path containing files
startFromintStarting index for renaming
extstringFile extension
RepairFilter(string)
txt files (.txt)|.txt|All files (.)|."
public static string RepairFilter(string filter)
Parameters
filterstring
Returns
ReplaceDiacriticRecursive(ILogger, string, bool, bool, DirectoryMoveCollisionOption, FileMoveCollisionOption)
Recursively removes diacritic marks from file and folder names.
public static void ReplaceDiacriticRecursive(ILogger logger, string folder, bool dirs, bool files, DirectoryMoveCollisionOption directoryCollisionOption, FileMoveCollisionOption fileCollisionOption)
Parameters
loggerILoggerLogger instance for diagnostic messages.
folderstringThe directory path.
dirsboolThe dirs parameter.
filesboolThe files parameter.
directoryCollisionOptionDirectoryMoveCollisionOptionThe directoryCollisionOption parameter.
fileCollisionOptionFileMoveCollisionOptionThe fileCollisionOption parameter.
ReplaceDirectoryThrowExceptionIfFromDoesntExists(string, string, string)
change all first (drive) letter to uppercase
public static string ReplaceDirectoryThrowExceptionIfFromDoesntExists(string path, string folderWithProjectsFolders, string folderWithTemporaryMovedContentWithoutBackslash)
Parameters
pathstringThe file or directory path.
folderWithProjectsFoldersstringfolderWithTemporaryMovedContentWithoutBackslashstring
Returns
ReplaceInAllFiles(IList<string>, IList<string>, ReplaceInAllFilesArgsBase, Func<string, bool>)
A4 - whether use text.Contains. A4 - SHReplace.ReplaceAll2
public static Task ReplaceInAllFiles(IList<string> replaceFrom, IList<string> replaceTo, ReplaceInAllFilesArgsBase args, Func<string, bool> EncodingHelperIsBinary)
Parameters
replaceFromIList<string>List of strings to find and replace.
replaceToIList<string>List of replacement strings.
argsReplaceInAllFilesArgsBaseArguments controlling the replacement behavior.
EncodingHelperIsBinaryFunc<string, bool>Function to determine if a file is binary.
Returns
ReplaceInAllFiles(string, string, ReplaceInAllFilesArgsBase, Func<string, bool>)
Replaces text in all specified files.
public static Task ReplaceInAllFiles(string from, string to, ReplaceInAllFilesArgsBase args, Func<string, bool> EncodingHelperIsBinary)
Parameters
fromstringThe from parameter.
tostringThe to parameter.
argsReplaceInAllFilesArgsBaseThe args parameter.
EncodingHelperIsBinaryFunc<string, bool>The EncodingHelperIsBinary parameter.
Returns
ReplaceInAllFiles(string, string, List<string>, List<string>, bool, Func<string, bool>)
Replaces text in all specified files.
public static Task ReplaceInAllFiles(string folder, string extension, List<string> replaceFrom, List<string> replaceTo, bool isMultilineWithVariousIndent, Func<string, bool> EncodingHelperIsBinary)
Parameters
folderstringThe directory path.
extensionstringThe extension parameter.
replaceFromList<string>The replaceFrom parameter.
replaceToList<string>The replaceTo parameter.
isMultilineWithVariousIndentboolThe isMultilineWithVariousIndent parameter.
EncodingHelperIsBinaryFunc<string, bool>The EncodingHelperIsBinary parameter.
Returns
ReplaceInFileName(string, string, string)
Náhrada za metodu ReplaceFileName se stejnými parametry
public static string ReplaceInFileName(string oldPath, string what, string forWhat)
Parameters
Returns
ReplaceIncorrectCharactersFile(string)
Replacement can be configured with replaceIncorrectFor
public static string ReplaceIncorrectCharactersFile(string path)
Parameters
pathstringThe file path to process
Returns
ReplaceIncorrectCharactersFile(string, string)
Pro odstranění špatných znaků odstraní všechny výskyty A2 za mezery a udělá z více mezere jediné
public static string ReplaceIncorrectCharactersFile(string path, string replaceAllOfThisThen)
Parameters
pathstringThe file path to process
replaceAllOfThisThenstringCharacters to replace with empty string
Returns
ReplaceIncorrectCharactersFile(string, string, string)
ReplaceIncorrectCharactersFile - can specify char for replace with ReplaceInvalidFileNameChars - all wrong chars skip A2 - can specify more letter in one string A3 is applicable only for A2. In general is use replaceIncorrectFor
public static string ReplaceIncorrectCharactersFile(string path, string replaceAllOfThisByA3, string replaceForThis)
Parameters
pathstringThe file path to process
replaceAllOfThisByA3stringCharacters to additionally replace
replaceForThisstringReplacement string
Returns
ReplaceInvalidFileNameChars(string, params char[])
ReplaceIncorrectCharactersFile - can specify char for replace with ReplaceInvalidFileNameChars - all wrong chars skip
public static string ReplaceInvalidFileNameChars(string filename, params char[] characters)
Parameters
filenamestringThe filename to process
characterschar[]Characters to keep even if they're invalid
Returns
- string
Filename with invalid characters removed
SaveMemoryStream(MemoryStream, string)
Saves a memory stream to a file.
public static void SaveMemoryStream(MemoryStream mss, string path)
Parameters
mssMemoryStreamThe mss parameter.
pathstringThe file or directory path.
SaveStream(string, Stream)
Saves a stream to a file at the specified path.
public static void SaveStream(string path, Stream text)
Parameters
ShrinkLongPath(string)
Shortens a long file path to a displayable length.
public static string ShrinkLongPath(string actualFilePath)
Parameters
actualFilePathstringThe actualFilePath parameter.
Returns
Slash(string, bool)
A2 true - bs to slash. false - slash to bs
public static string Slash(string path, bool slash)
Parameters
pathstringThe path to process
slashboolTrue to convert backslashes to slashes, false for opposite
Returns
SortPathsByFileName(List<string>, bool)
Sorts file paths alphabetically by their file name.
public static Dictionary<string, List<string>> SortPathsByFileName(List<string> allCsFilesInFolder, bool onlyOneExtension)
Parameters
allCsFilesInFolderList<string>The allCsFilesInFolder parameter.
onlyOneExtensionboolThe onlyOneExtension parameter.
Returns
StreamToArrayBytes(Stream)
Converts a stream to a byte array.
public static byte[] StreamToArrayBytes(Stream stream)
Parameters
streamStreamThe stream parameter.
Returns
- byte[]
ThrowNotImplementedUwp()
Throws a not-implemented exception for UWP-specific operations.
public static void ThrowNotImplementedUwp()
ToSearchOption(bool?)
Converts a nullable boolean to a SearchOption value.
public static SearchOption ToSearchOption(bool? recursive)
Parameters
recursivebool?The recursive parameter.
Returns
TrimBasePathAndTrailingBs(List<string>, string)
Removes the base path and trailing backslashes from a list of paths.
public static void TrimBasePathAndTrailingBs(List<string> text, string basePath)
Parameters
TrimContentInFilesOfFolder(string, string, SearchOption)
Trims whitespace from the content of all matching files in a folder.
public static void TrimContentInFilesOfFolder(string folder, string searchPattern, SearchOption searchOption)
Parameters
folderstringThe directory path.
searchPatternstringThe searchPattern parameter.
searchOptionSearchOptionThe searchOption parameter.
TryDeleteDirectory(string)
Before start you can create instance of PowershellRunner to try do it with PS
Vrátí true value případě chyby, jinak false
public static bool TryDeleteDirectory(string value)
Parameters
valuestringThe value to process.
Returns
TryDeleteDirectoryOrFile(string)
Attempts to delete a path whether it is a file or directory.
public static bool TryDeleteDirectoryOrFile(string value)
Parameters
valuestringThe value to process.
Returns
TryDeleteFile(string)
Attempts to delete a file, returning success status.
public static bool TryDeleteFile(string filePath)
Parameters
filePathstringThe file path.
Returns
TryDeleteFile(string, out string?)
Attempts to delete a file, returning success status.
public static bool TryDeleteFile(string filePath, out string? message)
Parameters
Returns
TryDeleteWithRepetition(string)
Pokusí se max. 10x smazat soubor A1, pokud se nepodaří, GF, jinak GT
public static bool TryDeleteWithRepetition(string filePath)
Parameters
filePathstringPath to the file to delete
Returns
WithEndSlash(string)
Ensures the path ends with a trailing backslash.
public static string WithEndSlash(string value)
Parameters
valuestringThe value to process.
Returns
WithEndSlash(ref string)
Usage: Exceptions.FileWasntFoundInDirectory
public static string WithEndSlash(ref string value)
Parameters
valuestringThe value to process.
Returns
WithoutEndSlash(string)
Removes trailing backslash from a path.
public static string WithoutEndSlash(string value)
Parameters
valuestringThe value to process.
Returns
WithoutEndSlash(ref string)
Removes trailing backslash from a path.
public static string WithoutEndSlash(ref string value)
Parameters
valuestringThe value to process.
Returns
WrapWithQm(string, bool?)
Wraps text with quote marks if needed
public static string WrapWithQm(string text, bool? forceNotIncludeQm)
Parameters
Returns
- string
Text wrapped with quote marks if needed
WriteAllText(string, string)
Writes text content to a file.
public static Task WriteAllText(string path, string content)
Parameters
Returns
WriteAllTextWithExc(string, string)
Writes all text to file with exception handling
public static Task WriteAllTextWithExc(string file, string content)