728x90
반응형
728x170
▶ 파일 경로 축약하기 예제
using System;
string sourcePath = @"D:\ARCA\DSCORE.COMMON\PROCESS\ProcessHelper.cs";
string targetPath = ShortenFilePath(sourcePath, 30);
Console.WriteLine("소스 파일 경로 : {0}", sourcePath);
Console.WriteLine("타겟 파일 경로 : {0}", targetPath);
728x90
▶ 파일 경로 축약하기
using System;
using System.Text;
using System.Linq;
#region 파일 경로 축약하기 - ShortenPath(fullFilePath, targetLength)
/// <summary>
/// 파일 경로 축약하기
/// </summary>
/// <param name="fullFilePath">완전한 파일 경로</param>
/// <param name="targetLength">타겟 길이</param>
/// <returns>축약 파일 경로</returns>
public string ShortenFilePath(string fullFilePath, int targetLength)
{
string targetPath = fullFilePath;
StringBuilder stringBuilder;
string[] partialPathArray;
int partialLength;
if(targetPath.Length > targetLength)
{
partialPathArray = targetPath.Split('\\');
partialLength = targetLength - 3 - (targetPath.Length - targetPath.LastIndexOf('\\'));
stringBuilder = new StringBuilder();
stringBuilder.Append(targetPath.Take(partialLength).ToArray());
stringBuilder.AppendFormat("...\\{0}", partialPathArray[partialPathArray.Length - 1]);
targetPath = stringBuilder.ToString();
}
return targetPath;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 도스 명령어 실행하기 (0) | 2018.10.22 |
---|---|
[C#/COMMON] WIN32 API를 사용해 디렉토리 크기 구하기 (0) | 2018.10.02 |
[C#/COMMON] DirectoryInfo 클래스 : GetDirectories 메소드를 사용해 디렉토리 크기 구하기 (0) | 2018.10.01 |
[C#/COMMON] WebClient 클래스 : HTTPS 파일 다운로드 하기 (0) | 2018.09.22 |
[C#/COMMON] DirectoryInfo 클래스 : EnumerateDirectories 메소드를 사용해 디렉토리 크기 구하기 (0) | 2018.09.21 |
[C#/COMMON] 파일 크기 문자열 구하기 (0) | 2018.09.17 |
[C#/COMMON] NTFS MFT를 사용해 디렉토리 크기 구하기 (0) | 2018.09.16 |
[C#/COMMON] DirectoryInfo 클래스 : EnumerateDirectories 메소드를 사용해 디렉토리 크기 구하기 (0) | 2018.09.13 |
[C#/COMMON] DirectoryInfo 클래스 : EnumerateFiles 메소드를 사용해 디렉토리 크기 구하기 (0) | 2018.09.13 |
[C#/COMMON] FSO를 사용해 디렉토리 크기 구하기 (0) | 2018.09.13 |
댓글을 달아 주세요