Show / Hide Table of Contents

    Class FileSupport

    Represents the methods to support some operations over files.

    Inheritance
    System.Object
    FileSupport
    Namespace: Lucene.Net.Support.IO
    Assembly: Lucene.Net.dll
    Syntax
    public static class FileSupport : object

    Methods

    | Improve this Doc View Source

    CreateTempFile(String, String)

    Creates a new empty file in a random subdirectory of , using the given prefix and suffix strings to generate its name.

    Declaration
    public static FileInfo CreateTempFile(string prefix, string suffix)
    Parameters
    Type Name Description
    System.String prefix

    The prefix string to be used in generating the file's name; must be at least three characters long

    System.String suffix

    The suffix string to be used in generating the file's name; may be null, in which case a random suffix will be generated

    Returns
    Type Description
    FileInfo

    A instance representing the temp file that was created.

    Remarks

    If this method returns successfully then it is guaranteed that:

    1. The file denoted by the returned abstract pathname did not exist before this method was invoked, and
    2. Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.
    This method provides only part of a temporary-file facility. However, the file will not be deleted automatically, it must be deleted by the caller.

    The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail".

    The suffix argument may be null, in which case a random suffix will be used.

    Both prefix and suffix must be provided with valid characters for the underlying system, as specified by .

    If the directory argument is null then the system-dependent default temporary-file directory will be used, with a random subdirectory name. The default temporary-file directory is specified by the method. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "C:\Users\[UserName]\AppData\Local\Temp".

    | Improve this Doc View Source

    CreateTempFile(String, String, DirectoryInfo)

    Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

    Declaration
    public static FileInfo CreateTempFile(string prefix, string suffix, DirectoryInfo directory)
    Parameters
    Type Name Description
    System.String prefix

    The prefix string to be used in generating the file's name; must be at least three characters long

    System.String suffix

    The suffix string to be used in generating the file's name; may be null, in which case a random suffix will be generated

    DirectoryInfo directory

    The directory in which the file is to be created, or null if the default temporary-file directory is to be used

    Returns
    Type Description
    FileInfo

    A instance representing the temp file that was created.

    Remarks

    If this method returns successfully then it is guaranteed that:

    1. The file denoted by the returned abstract pathname did not exist before this method was invoked, and
    2. Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.
    This method provides only part of a temporary-file facility. However, the file will not be deleted automatically, it must be deleted by the caller.

    The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail".

    The suffix argument may be null, in which case a random suffix will be used.

    Both prefix and suffix must be provided with valid characters for the underlying system, as specified by .

    If the directory argument is null then the system-dependent default temporary-file directory will be used, with a random subdirectory name. The default temporary-file directory is specified by the method. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "C:\Users\[UserName]\AppData\Local\Temp".

    | Improve this Doc View Source

    GetCanonicalPath(FileSystemInfo)

    Returns the absolute path of this with all references resolved and any drive letters normalized to upper case on Windows. An absolute path is one that begins at the root of the file system. The canonical path is one in which all references have been resolved. For the cases of '..' and '.', where the file system supports parent and working directory respectively, these are removed and replaced with a direct directory reference.

    Declaration
    public static string GetCanonicalPath(this FileSystemInfo path)
    Parameters
    Type Name Description
    FileSystemInfo path

    This instance.

    Returns
    Type Description
    System.String

    The canonical path of this file.

    | Improve this Doc View Source

    IsFileAlreadyExistsException(Exception, String)

    Tests whether the passed in is an corresponding to the underlying operating system's "File Already Exists" violation. This works by forcing the exception to occur during initialization and caching the value for the current OS.

    Declaration
    public static bool IsFileAlreadyExistsException(Exception ex, string filePath)
    Parameters
    Type Name Description
    Exception ex

    An exception, for comparison.

    System.String filePath

    The path of the file to check. This is used as a fallback in case the current OS doesn't have an HResult (an edge case).

    Returns
    Type Description
    System.Boolean

    true if the exception passed is an with an corresponding to the operating system's "File Already Exists" violation, which occurs when an attempt is made to create a file that already exists.

    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)