코딩을 하다보면 파일명이나 폴더명을 파라메터로 주고받는 함수를 만들경우가 많은데, 이때 명칭을 제대로 통일시키지 못해서 곤란한 경우가 많았다. 그래서 한번 정리해 봤다.


* folder 와 directory 용어
도스시절에는 directory 였는데,  윈도우로 넘어오면서 folder 라는 말을 쓰기 시작했고.... 그때부더 혼란이 오기 시작했다.

구글에서도 folder vs directory 로 검색해 보면 외국인들도 두 용어의 사용에 혼란(?)을 겪고 있는듯하다.  일단 나는 글자수가 더 적은(-.-) folder 를 선택하기로 했다.

* path 용어
path 는 파일이나 폴더의 경로명을 뜻한다. 즉

- c:\temp
- c:\temp\test.txt

전자는 폴더의 path, 후자는 파일의 path 이다. 문제는 path 는 절대 경로 뿐만 아니라 상대 경로도 포함한다. 따라서

- ..\..\temp\test.xt

도 path 명이다.



* win32 api 살펴보기

폴더를 파라메터로 받는 api 들은 대부분 pathname 이라고 되어 있고, 파일을 파라메터로 받는 경우는 전체 경로 뿐만 아니라, 상대경로도 가능하기 때문에 그냥 filename 으로 되어 있다.  full path file name 를 처리하는 경우에도 그냥 fileName 을 파라메터로 쓰는경우가 많다.

BOOL RemoveDirectory(
  LPCTSTR lpPathName
); 
BOOL PathIsDirectory(      
    LPCTSTR pszPath
);
BOOL CopyFile(
  LPCTSTR lpExistingFileName, 
  LPCTSTR lpNewFileName, 
  BOOL bFailIfExists 
); 
HANDLE CreateFile(
  LPCTSTR lpFileName, 
  DWORD dwDesiredAccess, 
  DWORD dwShareMode, 
  LPSECURITY_ATTRIBUTES lpSecurityAttributes, 
  DWORD dwCreationDisposition, 
  DWORD dwFlagsAndAttributes, 
  HANDLE hTemplateFile
); 
int _mkdir(
   const char *dirname 
);
FILE *fopen( 
   const char* filename, 
   const char* mode 
);
UINT WINAPI GetSystemDirectory(
  __out         LPTSTR lpBuffer,
  __in          UINT uSize
);
BOOL PathFileExists(      
    LPCTSTR pszPath
);

DWORD WINAPI GetModuleFileName(
  __in          HMODULE hModule,
  __out         LPTSTR lpFilename,
  __in          DWORD nSize
);
...A pointer to a buffer that receives the fully-qualified path of the module. ....

DWORD WINAPI GetFullPathName(
  __in          LPCTSTR lpFileName,
  __in          DWORD nBufferLength,
  __out         LPTSTR lpBuffer,
  __out         LPTSTR* lpFilePart
);


* 내가 만든 규칙
이상을 참고해서 다음은 앞으로 내가 코딩할 때 사용할 규칙이다. win32 api 나 다른 사람의 규칙과는 상관이 없으므로 이 글을 읽는 사람은 별 의미는 부여하지 말고 그냥 참고만 하면 되겠다.

- fileName
파일명을 파라메터로 받을 때 사용한다. 이때 파일명에 경로는 포함되지 않는다.
예: 
test.txt

- folderName
폴더를 파라메터로 받을 때 사용한다. 이때 폴더명에 경로는 포함되지 않는다.
예: 
test\
test

- filePathName
경로를 포함한 파일명을 파라메터로 받을 때 사용한다.
예:
test.txt
c:\test.txt
..\test.txt

- folderPathName
경로를 포함한 폴더명을 파라메터로 받을 때 사용한다.
예:
c:\
c:\temp
..\temp\

- pathName
경로를 포함한 폴더 혹은 파일을 파라메터로 받을 때 사용한다.
예:
c:\temp\
c:\temp\test.txt
..\temp\test.txt

- fullPathFileName
절대경로 파일명을 파라메터로 받는다.
예:
c:\temp\test.txt

- fullPathFolderName
절대경로 폴더명을 파라메터로 받는다.
예:
c:\temp\

- fullPathName
절대 경로 폴더 혹은 파일명을 파라메터로 받는다.
예:
c:\temp\
c:\temp\test.txt




Posted by 키플러