{"id":109,"date":"2010-04-17T22:54:28","date_gmt":"2010-04-18T07:54:28","guid":{"rendered":"\/blog\/?p=109"},"modified":"2023-09-21T09:41:15","modified_gmt":"2023-09-21T00:41:15","slug":"directory-depth-%ea%b5%ac%ed%95%98%eb%8a%94-%ed%95%a8%ec%88%98-vc","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=109","title":{"rendered":"Directory Depth \uad6c\ud558\ub294 \ud568\uc218 (VC)"},"content":{"rendered":"\n<DIV style=\"FONT-FAMILY: 1092568_9; FONT-SIZE: 9pt\" class=view>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">DWORD QueryMaximumDepthofSomePath(LPCTSTR lpszPath)<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;WIN32_FIND_DATA wfs;<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;HANDLE hFile = NULL;<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;TCHAR FullDirPath[MAX_PATH];<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;TCHAR NewDirPath[MAX_PATH];<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;ZeroMemory(FullDirPath, sizeof(FullDirPath));<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;ZeroMemory(NewDirPath, sizeof(NewDirPath));<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;int nCount = 1; &nbsp; &nbsp; &nbsp;\/\/\ub514\ub809\ud1a0\ub9ac \uae4a\uc774 (\uc785\ub825\ubc1b\uc740 lpszPath \ubd80\ud130 \uce74\uc6b4\ud2b8 \ud55c\ub2e4.)<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;int nTotCount = 0; &nbsp; &nbsp; \/\/\ucd5c\ud558\uc704 \ub514\ub809\ud1a0\ub9ac \uae4a\uc774<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;\/\/ \ud3f4\ub354\uac00 \uc874\uc7ac \ud558\ub294\uc9c0, \ub4dc\ub77c\uc774\ube0c\uc778\uc9c0 \uccb4\ud06c<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;if ( PathIsRoot(lpszPath) || _access(lpszPath, 0) == -1 )<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; return 0;<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;}<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;wsprintf(FullDirPath,<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp; \"%s\\\\*.*\",lpszPath);<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;\/\/ Start scaning the directory<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;hFile = FindFirstFile(FullDirPath, &amp;wfs);<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;\/\/ Check the return handle value<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;do<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; \/\/ Check is the current found file is directory?<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; if ((FILE_ATTRIBUTE_DIRECTORY &amp; wfs.dwFileAttributes))<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; {<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;if( lstrcmp(wfs.cFileName,\".\") == 0 ){}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;else if( lstrcmp(wfs.cFileName,\"..\") == 0 ){}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;else<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp; wsprintf(NewDirPath, \"%s\\\\%s\", lpszPath, wfs.cFileName);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp; subDepthDirecty(NewDirPath, &amp;nCount, &amp;nTotCount);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; }<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; <\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; \/\/ Scan the next match item in the directory<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; if (!FindNextFile(hFile, &amp;wfs))<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; {<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;if (ERROR_NO_MORE_FILES == GetLastError()) {break;}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; }<\/SPAN><\/FONT><\/P>\n<P><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\"><FONT face=\"GulimChe, Sans-serif\">&nbsp;} while (NULL != hFile || INVALID_HANDLE_VALUE != hFile);<\/FONT><\/SPAN><\/P>\n<P><br \/><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;if (NULL != hFile)<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; FindClose(hFile);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;hFile = NULL;<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;return nTotCount;<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">}<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><\/FONT>&nbsp;<\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><\/FONT>&nbsp;<\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><\/FONT>&nbsp;<\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">void subDepthDirecty(LPCTSTR szPath, int* pCount, int* pTotCount)<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;HANDLE hFile;<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;WIN32_FIND_DATA&nbsp; fData;<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;TCHAR FullDirPath[MAX_PATH];<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;TCHAR NewDirPath[MAX_PATH];<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;BOOL bResult = TRUE;<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;(*pCount)++;<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;wsprintf(FullDirPath, \"%s\\\\*.*\", szPath);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;hFile = FindFirstFile(FullDirPath, &amp;fData);<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;while(bResult)<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; if ((FILE_ATTRIBUTE_DIRECTORY &amp; fData.dwFileAttributes))<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; {<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;if( lstrcmp(fData.cFileName,\".\") == 0 ){}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;else if( lstrcmp(fData.cFileName,\"..\") == 0 ){}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;else<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp; wsprintf(NewDirPath, \"%s\\\\%s\", szPath, fData.cFileName);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp; subDepthDirecty(NewDirPath, &amp;(*pCount), &amp;(*pTotCount));<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;\/\/\ud3f4\ub354 \uae4a\uc774\uc640 \uc774\uc804 \ucd5c\ud558\uc704 \ud3f4\ub354 \uae4a\uc774 \ube44\uad50<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;if( (*pTotCount) &lt; (*pCount) ) &nbsp; &nbsp; <\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;{<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp; (*pTotCount) = (*pCount);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; &nbsp;}<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; }<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp; bResult = FindNextFile(hFile, &amp;fData);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;}<\/SPAN><\/FONT><\/P>\n<P><FONT face=\"GulimChe, Sans-serif\"><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;FindClose(hFile);<\/SPAN><br \/><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\">&nbsp;(*pCount)--;<\/SPAN><br \/><\/FONT><SPAN style=\"FONT-FAMILY: \uad74\ub9bc\uccb4\"><FONT face=\"GulimChe, Sans-serif\">} <\/FONT>\n<DIV class=autosourcing-stub><\/DIV><\/SPAN>\n<P><\/P><\/DIV>\n","protected":false},"excerpt":{"rendered":"<p>DWORD QueryMaximumDepthofSomePath(LPCTSTR lpszPath){&nbsp;WIN32_FIND_DATA wfs;&nbsp;HANDLE hFile = NULL; &nbsp;TCHAR FullDirPath[MAX_PATH];&nbsp;TCHAR NewDirPath[MAX_PATH];&nbsp;ZeroMemory(FullDirPath, sizeof(FullDirPath));&nbsp;ZeroMemory(NewDirPath, sizeof(NewDirPath)); &nbsp;int nCount = 1; &nbsp; &nbsp; &nbsp;\/\/\ub514\ub809\ud1a0\ub9ac \uae4a\uc774 (\uc785\ub825\ubc1b\uc740 lpszPath \ubd80\ud130 \uce74\uc6b4\ud2b8 \ud55c\ub2e4.)&nbsp;int nTotCount = 0; &nbsp; &nbsp; \/\/\ucd5c\ud558\uc704 \ub514\ub809\ud1a0\ub9ac \uae4a\uc774 &nbsp;\/\/ \ud3f4\ub354\uac00 \uc874\uc7ac \ud558\ub294\uc9c0, \ub4dc\ub77c\uc774\ube0c\uc778\uc9c0 \uccb4\ud06c&nbsp;if ( PathIsRoot(lpszPath) || _access(lpszPath, 0) == -1 )&nbsp;{&nbsp; return 0;&nbsp;} &nbsp;wsprintf(FullDirPath,&nbsp; &nbsp; &#8220;%s\\\\*.*&#8221;,lpszPath); &nbsp;\/\/ Start scaning [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-development_language"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=109"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}