Class FileUtils

wwUtils class which contains a set of common utility classes for Formatting strings Reflection Helpers Object Serialization Stream Manipulation

System.Object
  Westwind.Utilities.FileUtils
public static class FileUtils : object

Class Members

MemberDescription

AddTrailingSlash

Adds a trailing slash to a path if there isn't one.

public static string AddTrailingSlash(string path)

public static string AddTrailingSlash(string path,     char slashChar)

CamelCaseSafeFilename

Returns a safe filename in CamelCase

public static string CamelCaseSafeFilename(string filename)

CopyDirectory

Copies directories using either top level only or deep merge copy.

public static void CopyDirectory(string sourceDirectory,     string targetDirectory,     bool deleteFirst,     bool recursive)

public static void CopyDirectory(DirectoryInfo source,     DirectoryInfo target,     bool deleteFirst,     bool recursive)

CopyStream

Copies the content of the one stream to another. Streams must be open and stay open.

public static void CopyStream(Stream source,     Stream dest,     int bufferSize)

public static void CopyStream(Stream source,     Stream dest,     int bufferSize,     bool append)

DeleteFiles

Deletes files in a folder based on a file spec recursively

public static int DeleteFiles(string path,     string filespec,     bool recursive)

DeleteTimedoutFiles

Deletes files based on a file spec and a given timeout. This routine is useful for cleaning up temp files in Web applications.

public static void DeleteTimedoutFiles(string filespec,     int seconds)

ExpandPathEnvironmentVariables

Expands Path Environment Variables like %appdata% in paths.

public static string ExpandPathEnvironmentVariables(string path)

FilePathAsUrl

Returns a path as a file:/// url.

public static string FilePathAsUrl(string path)

FindFileInHierarchy

public static string FindFileInHierarchy(string currentPath,     string searchFile,     FindFileInHierarchyDirection direction)

FindFilesInHierarchy

public static String[] FindFilesInHierarchy(string startPath,     string searchFile,     FindFileInHierarchyDirection direction)

GetChecksumFromFile

Creates an MD5 checksum of a file

public static string GetChecksumFromFile(string file,     string hashAlgorithm)

GetCompactPath

Returns a compact path with elipsis from a long path

public static string GetCompactPath(string path,     int length)

GetFileEncoding

Detects the byte order mark of a file and returns an appropriate encoding for the file.

public static Encoding GetFileEncoding(string srcFile)

GetPhysicalPath

This function returns the actual filename of a file that exists on disk. If you provide a path/file name that is not proper cased as input, this function fixes it up and returns the file using the path and file names as they exist on disk.

public static string GetPhysicalPath(string filename)

GetRelativePath

Returns a relative path string from a full path based on a base path provided.

public static string GetRelativePath(string fullPath,     string basePath)

GetShortPath

Returns a short form Windows path (using ~8 char segment lengths) that can help with long filenames.

public static string GetShortPath(string path)

GetTempFilenameWithExtension

Creates a temporary file name with a specific extension. Optionall provide the base path to create it in otherwise the TEMP path is used. Filename is generated as _ + 8 random characters/digits

public static string GetTempFilenameWithExtension(string extension,     string tempPath,     int charCount)

HasInvalidPathCharacters

Checks to see if a file has invalid path characters. Use this to check before using or manipulating paths with Path operations that will fail if files or paths contain invalid characters.

public static bool HasInvalidPathCharacters(string path,     Char[] additionalChars)

NormalizeDirectory

Normalizes path with slashes and forces a trailing slash on the end of the path.

public static string NormalizeDirectory(string path)

NormalizePath

Normalizes a file path to the operating system default slashes.

public static string NormalizePath(string path)

OpenStreamReaderWithEncoding

Opens a stream reader with the appropriate text encoding applied.

public static StreamReader OpenStreamReaderWithEncoding(string srcFile)

ReadAllTextAsync

Asynchronously reads files. Use only with NetFx

public static Task ReadAllTextAsync(string filename,     Encoding encoding)

SafeFilename

Returns a safe filename from a string by stripping out illegal characters

public static string SafeFilename(string fileName,     string replacementString,     string spaceReplacement)

WriteAllTextAsync

Writes out text file content asynchronously.Use only with NetFx.

public static Task WriteAllTextAsync(string filename,     string text,     Encoding encoding)

Requirements

Namespace: Westwind.Utilities
Assembly: westwind.utilities.dll

© West Wind Technologies, 1996-2024 • Updated: 06/29/24
Comment or report problem with topic