안녕하세요?
아별닷컴의 주인장 오주원입니다.
아별툴을 사용하다가..
원하는 결과물이 안 나와서 살펴보니.. 에러가 있어서 수정하면서 알게된 팁을 공유합니다.
아별툴에는 특정 폴더의 파일 리스트를 생성해주는 기능이 있습니다.
아별툴 리본메뉴 > 정보 > "특정 폴더의 파일 리스트 생성" 을 클릭하면 파일 리스트를 생성할 수 있습니다.
원래는 하위 폴더를 포함해서 생성하도록 프로그래밍했는데,
어째선지 최 상위 폴더의 리스트만 만들어서 확인해보니 GetAttr()함수의 리턴값이 예상 외의 값을 리턴하는 것이었습니다.
원래 코드는 아래와 같았습니다.
If GetAttr(Path & strFile) = vbDirectory Then
특정 경로의 파일 또는 폴더의 속성이 디렉토리(vbDirectory)이면 그 하위 폴더를 검색하는 작업을 하게 했는데,
GetAttr(Path & strFile)의 결과값이 vbDirectory의 값이 16이 아니라 8208이 나오는 것입니다.
그래서 하위 폴더를 모두 패스해버리더군요..
그래서 검색해보니 아래와 같은 안내가 있었습니다.
http://www.tek-tips.com/viewthread.cfm?qid=751597
Private Const FILE_ATTRIBUTE_DIRECTORY = 16
Private Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192
위 두개 상수를 더해서 8192+16 = 8208이 나온 것이라구요..
그래서 해당 경로의 속성에 폴더의 속성이 포함된건지 확인하려면 아래와 같이 해야한다고 하네요..
If (GetAttr(Path & strFile) And vbDirectory) = vbDirectory Then
위와 같이 수정해서 하위 폴더도 잘 검색되도록 업데이트했습니다.
수정된 아별툴은 몇가지를 더 수정해서 공개하도록 하겠습니다.
도움이 되셨기를..
참고로)
디렉토리가 아닌 파일의 경우는 GetAttr(Path & strFile) And vbDirectory 의 결과값이 0이 나옵니다.
디렉토리는 GetAttr(Path & strFile) And vbDirectory의 결과값이 16이 리턴을 합니다.
Visual Basic의 팁이지만, 같은 내용이니 아래 링크의 MSDN문서도 확인해보세요..
https://msdn.microsoft.com/en-us/library/hds568h4(v=vs.90).aspx
' Test for normal.
If (MyAttr And FileAttribute.Normal) = FileAttribute.Normal Then
MsgBox("This file is normal.")
End If
' Test for normal and readonly.
Dim normalReadonly As FileAttribute
normalReadonly = FileAttribute.Normal Or FileAttribute.ReadOnly
If (MyAttr And normalReadonly) = normalReadonly Then
MsgBox("This file is normal and readonly.")
End If
' Assume MYDIR is a directory or folder.
MyAttr = GetAttr("C:\MYDIR")
If (MyAttr And FileAttribute.Directory) = FileAttribute.Directory Then
MsgBox("MYDIR is a directory")
End If