C# 클래스 LazyCopy.Utilities.PathHelper

Contains helper functions to work with file system.
파일 보기 프로젝트 열기: aleksk/LazyCopy

공개 메소드들

메소드 설명
ChangeDeviceNameToDriveLetter ( string path ) : string

Changes the DOS device name for the path given to the according drive letter.

This method also supports UNC paths.

ChangeDriveLetterToDeviceName ( string path ) : string

Changes the drive letter for the path given to the according DOS device name.

This method also supports UNC paths.

ChangeParent ( string path, string oldParent, string newParent ) : string

Changes the parent of a path string.

This method is useful, when you need not just replace the path root, but one of its parent.
For example, to transform C:\Source\SubDir\File.txt into D:\Target\SubDir\File.txt the following code may be used: string targetFile = PathHelper.ChangeParent(@"C:\Source\File.txt", @"C:\Source", @"D:\Target");

CompactPath ( string longPathName, int newLength ) : string

Truncates a path to fit within a certain number of characters by replacing path components with ellipses.

The '/' separator will be used instead of '\' if the original string used it.
If longPathName points to a file name that is too long, instead of a path, the file name will be truncated to newLength characters, including the ellipsis and the terminating character.
For example, if the input file name is "My Filename" and newLength is 10, this method will return "My Fil...".

EndWithDirectorySeparator ( string path ) : string

Makes sure that the path ends with the directory separator.

GenerateUniqueFileName ( string parentDirectory, string prefix, string extension ) : string

Generates unique file name in the parentDirectory.

The result file name will look like the following: <prefix><GUID>.<extension>
For example:
PathHelper.GenerateUniqueFileName(@"C:\Temp\", "a_", "bin"); // C:\Temp\a_8F3C680522E0457896837ADF38ED8E6A.bin PathHelper.GenerateUniqueFileName(@"C:\Temp\", "b_", ".txt"); // C:\Temp\b_BF3C086BE0C444B4906E4A36CBC16551.txt

GetFileNameWithoutExtension ( string path, string extension ) : string

Returns the file name of the specified path string without the extension.

If the path does not end with the extension, its original value is returned.

비공개 메소드들

메소드 설명
GetDeviceDosName ( string rootPath ) : string

Queries OS for the device name.

UpdateDeviceMappings ( ) : void

Updates the internal maps between the volume names (D:\) and device names (\Device\HarddiskVolume2\).

메소드 상세

ChangeDeviceNameToDriveLetter() 공개 정적인 메소드

Changes the DOS device name for the path given to the according drive letter.
This method also supports UNC paths.
is or empty. does not start with a DOS device name. Drive letter could not be found for the given.
public static ChangeDeviceNameToDriveLetter ( string path ) : string
path string Path to replace DOS device name for.
리턴 string

ChangeDriveLetterToDeviceName() 공개 정적인 메소드

Changes the drive letter for the path given to the according DOS device name.
This method also supports UNC paths.
is or empty. is too short. The according DOS device name could not be found.
public static ChangeDriveLetterToDeviceName ( string path ) : string
path string Path to replace the drive letter for.
리턴 string

ChangeParent() 공개 정적인 메소드

Changes the parent of a path string.
This method is useful, when you need not just replace the path root, but one of its parent.
For example, to transform C:\Source\SubDir\File.txt into D:\Target\SubDir\File.txt the following code may be used: string targetFile = PathHelper.ChangeParent(@"C:\Source\File.txt", @"C:\Source", @"D:\Target");
Any of the parameters is or empty. string does not start with the .
public static ChangeParent ( string path, string oldParent, string newParent ) : string
path string The path information to modify.
oldParent string The old parent.
newParent string The new parent.
리턴 string

CompactPath() 공개 정적인 메소드

Truncates a path to fit within a certain number of characters by replacing path components with ellipses.
The '/' separator will be used instead of '\' if the original string used it.
If longPathName points to a file name that is too long, instead of a path, the file name will be truncated to newLength characters, including the ellipsis and the terminating character.
For example, if the input file name is "My Filename" and newLength is 10, this method will return "My Fil...".
is or empty. is negative or equal to zero. cannot be compacted.
public static CompactPath ( string longPathName, int newLength ) : string
longPathName string Path to be altered.
newLength int The maximum number of characters to be contained in the new string.
리턴 string

EndWithDirectorySeparator() 공개 정적인 메소드

Makes sure that the path ends with the directory separator.
is or empty.
public static EndWithDirectorySeparator ( string path ) : string
path string The path information to modify.
리턴 string

GenerateUniqueFileName() 공개 정적인 메소드

Generates unique file name in the parentDirectory.
The result file name will look like the following: <prefix><GUID>.<extension>
For example:
PathHelper.GenerateUniqueFileName(@"C:\Temp\", "a_", "bin"); // C:\Temp\a_8F3C680522E0457896837ADF38ED8E6A.bin PathHelper.GenerateUniqueFileName(@"C:\Temp\", "b_", ".txt"); // C:\Temp\b_BF3C086BE0C444B4906E4A36CBC16551.txt
is .
public static GenerateUniqueFileName ( string parentDirectory, string prefix, string extension ) : string
parentDirectory string Directory, where the file will be stored into.
prefix string File prefix. May be .
extension string File extension. May be .
리턴 string

GetFileNameWithoutExtension() 공개 정적인 메소드

Returns the file name of the specified path string without the extension.
If the path does not end with the extension, its original value is returned.
or is or empty.
public static GetFileNameWithoutExtension ( string path, string extension ) : string
path string Path to the file.
extension string Extension to be removed (with or without leading dot), if the has it.
리턴 string