tags:

views:

67

answers:

2

I'm working on a C++ program that will automatically backup my work to my FTP server. So far I am able to upload a single file, by specifying a file name using this

CString strFilePath = szFile ;
            int iPos = strFilePath.ReverseFind('\\');
            CString strFileName = strFilePath.Right((strFilePath.GetLength()- iPos-1) );

            CString strDirPath = m_szFolderDroppedIn ;
            strDirPath = strDirPath.Mid(0,strDirPath.GetLength() - 1);  
            int iPost = strDirPath.ReverseFind('\\');
            CString strDirName = strDirPath.Right((strDirPath.GetLength()- iPost -1) );

            bool curdir = ftpclient.SetServerDirectory((char*)strDirName.GetBuffer(strDirName.GetLength())); 

            //Upload to Server 
            int uploadret = ftpclient.PutFile(szFile,(char*)strFileName.GetBuffer(strFileName.GetLength()),0,true,dwLastError); 
            m_lsDroppedFiles.RemoveAll();
            break;
            }

Now I want to be able to iterate through a directory (Which contains subdirectories) and recursively call. I'm having a problem getting a hold of the files in the directory.

Any help or code snippet...

+1  A: 

Since you are using MFC, you can use the CFileFind class. Example code is given in MSDN. Alternatively, you can use boost.filesystem for the same.

Naveen
@Naveen : That's fine but i want to find out files present inside the directories. How to do that ?
Swapnil Gupta
@Swapnil: See the sample code in MSDN. It is doing a recursive search of `C:\\`
Naveen
A: 

@Swapnil: If you use boost::filesystem, there is a recursive_directory_iterator

SilverSun