+ Reply to Thread
Results 1 to 2 of 2

Thread: How to get list of hidden files from specified directory?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    26

    How to get list of hidden files from specified directory?

    I have a requirement where I need to get the list of hidden files from the specified directory.

    Also, it should be recursive.

    How can I do this in WIN32 or MFC?

    Any help?

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    27
    You can use CFileFind class from MFC library.

    Code:
    void GetHiddenFiles(CString strDirectory, CArray<CString, CString>& strHiddenFiles)
    {
    	strDirectory += "\\*.*" ;
    	CFileFind objFinder ;
    	BOOL bWorking = objFinder.FindFile(strDirectory) ;
    	while (bWorking)
    	{
    		bWorking = objFinder.FindNextFile() ;
    		if (!objFinder.IsDots())
    		{
    			
    			if (objFinder.IsDirectory())
    			{
    				GetHiddenFiles(objFinder.GetFilePath(), strHiddenFiles) ;
    			}
    			else if (objFinder.IsHidden())
    			{
    				strHiddenFiles.Add(objFinder.GetFileName()) ;
    			}
    		}
    	}
    	objFinder.Close() ;
    }
    
    void CMyDlg::OnBnClickedOk()
    {
    	CArray<CString, CString> strHiddenFiles ;
    	CString strDirectory = _T("D:\\Code") ;
    	GetHiddenFiles(strDirectory, strHiddenFiles) ;
    }
    I hope this will help you.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts