CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: how find files

  1. #1
    Join Date
    Dec 2002
    Location
    Moscow
    Posts
    8

    Question how find files

    How find files in folder with subfolders by mask and copy this files in other folder with the same subfolders?
    What class?
    or maybe write code, plz

  2. #2
    Join Date
    Aug 2002
    Location
    germany
    Posts
    112

    files

    hey, you can use the api, there' re functions to search files, code a few lines, you' ll be able to write your own class that solves your problems, use FindFirstFile(), FindNextFile(), use the structure, they put their returns in, so you can handle files and folders

  3. #3
    Join Date
    Aug 2002
    Location
    germany
    Posts
    112

    files

    hey, let me know, when you need more help

  4. #4
    Join Date
    Dec 2002
    Location
    Moscow
    Posts
    8
    i used class CFindFile... there are some function FindFile() and FindNextFile() in this class... did you talked about this functions?

  5. #5
    Join Date
    Aug 2002
    Location
    germany
    Posts
    112

    files

    they' ve got the same name, but i' m not shure that they are the same, the mfc encapsulate the api functions, so they might be identical, did you get any results, are you going to solve it

  6. #6
    Join Date
    Aug 2002
    Location
    germany
    Posts
    112

    files

    hey, Andreas Masur gave me that when i was trying to detect if a file exists or not:

    CString szPath("c:\\windows");

    DWORD dwAttr = GetFileAttributes(szPath);
    if (dwAttr == 0xffffffff)
    {
    DWORD dwError = GetLastError();
    if (dwError == ERROR_FILE_NOT_FOUND)
    {
    // file not found
    }
    else if (dwError == ERROR_PATH_NOT_FOUND)
    {
    // path not found
    }
    else if (dwError == ERROR_ACCESS_DENIED)
    {
    // file or directory exists, but access is denied
    }
    else
    {
    // some other error has occured
    }
    }
    else
    {
    if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
    {
    // this is a directory
    }
    else
    {
    // this is an ordinary file
    }
    }

    maybe that is another start for you

  7. #7
    Join Date
    Dec 2002
    Location
    Moscow
    Posts
    8

    files

    thanks, that is what i need

  8. #8
    Join Date
    Dec 2002
    Location
    Moscow
    Posts
    8

    files

    i used this...

    void CBackup::FindFileBckp( CString path, CString mask )
    {
    CFileFind finder;
    path+=_T( "\\" )+mask;
    BOOL bFinding = finder.FindFile( path );
    while( bFinding )
    {
    bFinding=finder.FindNextFile();
    if( finder.IsDirectory() )
    {
    CString str = finder.GetFilePath();
    FindFileBckp( str, mask );
    }
    else
    {
    CString article=path;
    int len=article.GetLength();
    int temp=article.Delete( 0,len );
    temp=article.Delete( temp-4,3 );
    CopyFileBckp( finder.GetFilePath(),myPath,article );
    }
    }
    finder.Close();
    };



    this function goes in cycles why i don't know

  9. #9
    Join Date
    Sep 2002
    Posts
    77
    Hi,

    I can imagine that depending on your mask FindFile and FindNextFile will find the "." and ".." directories, too.
    As long as you have no special handling for these you will get an endless loop.

  10. #10
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: files

    Originally posted by vovkin
    i used this...

    <snipped code>

    this function goes in cycles why i don't know
    As alpha137 mentioned you need to check for the '.' and '..' first otherwise you will recur infinitely...thus...
    Code:
    void CBackup::FindFileBckp( CString path, CString mask )
    {
      CFileFind finder;
    
      path += _T("\\") + mask;
      
      BOOL bFinding = finder.FindFile(path);
      while(bFinding)
      {
        bFinding = finder.FindNextFile();
    
        if(finder.IsDots())
          continue;
        
        if(finder.IsDirectory())
        {
          CString str = finder.GetFilePath();
          FindFileBckp(str, mask);
        }
        else
        {
          CString article = path;
          int     len     = article.GetLength();
    
          int temp = article.Delete(0, len);
          temp     = article.Delete(temp - 4, 3);
    
          CopyFileBckp(finder.GetFilePath(), myPath, article);
        }
      }
    
      finder.Close();
    };

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured