Showing posts with label _splitpath. Show all posts
Showing posts with label _splitpath. Show all posts
2011/07/28
[C#] 경로 요소 분리하기
C++ 에는 _splitpath 라는 멋진 함수가 있어서 전체 경로에서 구성 요소(드라이브, 패스, 파일명, 확장자)를 분리할 수 있었다.
C#에서 이용할 수 있는 함수가 있나 찾아 보았는데 함수는 없고 보다 많은 기능을 포함하고 있는 객체를 찾았다.
System.IO.Path 인데 이 녀석은 경로에 관련한 많은 기능을 담고 있다.
아래 코드는 MSDN에서 발췌해 온 예제 코드 이다.
public static void Main()
{
string path1 = @"c: emp\MyTest.txt";
string path2 = @"c: emp\MyTest";
string path3 = @"temp";
if (Path.HasExtension(path1))
{
Console.WriteLine("{0} has an extension.", path1);
}
if (!Path.HasExtension(path2))
{
Console.WriteLine("{0} has no extension.", path2);
}
if (!Path.IsPathRooted(path3))
{
Console.WriteLine("The string {0} contains no root information.", path3);
}
Console.WriteLine("The full path of {0} is {1}.", path3, Path.GetFullPath(path3));
Console.WriteLine("{0} is the location for temporary files.", Path.GetTempPath());
Console.WriteLine("{0} is a file available for use.", Path.GetTempFileName());
/* This code produces output similar to the following:
* c: emp\MyTest.txt has an extension.
* c: emp\MyTest has no extension.
* The string temp contains no root information.
* The full path of temp is D:\Documents and Settings\cliffc\...\Debug emp.
* D:\Documents and Settings\cliffc\Local Settings\Temp...\ is the location for temporary files.
* D:\Documents and Settings\cliffc\Local Settings\Temp... temp3D.tmp is a file available for use.
*/
}
MSDN의 Path 클래스 설명 페이지 <
Original Post : http://neodreamer-dev.tistory.com/557
Labels:
_splitpath
,
c#
,
CSharp
,
Path Class
,
System.IO.Path
,
TistoryOldPost
2010/03/23
실행 파일의 경로 가져오기 _splitpath
TCHAR filename[MAX_PATH];
GetModuleFileName(NULL, filename, sizeof(filename));
TCHAR Drive[_MAX_DRIVE];
TCHAR Path[_MAX_DIR];
TCHAR Filename[_MAX_FNAME];
TCHAR Ext[_MAX_EXT];
_tsplitpath_s(filename, Drive, _MAX_DRIVE, Path, _MAX_DIR, Filename, _MAX_FNAME, Ext, _MAX_EXT);MSDN 의 _splitpath 설명보기
void _splitpath(
const char *path,
char *drive,
char *dir,
char *fname,
char *ext
);
Parameters
path
Full path
drive
Optional drive letter, followed by a colon (:)
dir
Optional directory path, including trailing slash. Forward slashes ( / ),
backslashes ( \ ), or both may be used.
fname
Base filename (no extension)
ext
Optional filename extension, including leading period (.)
Remarks
The _splitpath function breaks a path into its four components. _splitpath automatically handles multibyte-character string arguments as appropriate, recognizing multibyte-character sequences according to the multibyte code page currently in use. _wsplitpath is a wide-character version of _splitpath; the arguments to _wsplitpath are wide-character strings. These functions behave identically otherwise
출처 : MSDN
Original Post : http://neodreamer-dev.tistory.com/387
Labels:
_splitpath
,
GetModuleFileName
,
TistoryOldPost
,
실행파일 경로
,
자신의 경로
Subscribe to:
Posts
(
Atom
)