Re: HINT: download all files from remote folder - WeOnlyDo Discussion board

Re: HINT: download all files from remote folder (General questions)

by sumeetkoshal, Tuesday, January 04, 2005, 11:05 (7262 days ago) @ wodSupport

Hi,
U can write following piece of code in VC to do the same.
write a function called FindFiles which will return List of all the
files [',' SEPARATED] in a given directory except directory in it.
ex:
BOOL FindFiles(CString sDir, CString & sList)
{
CString sFiles;
BSTR bstrList;
USES_CONVERSION;
HRESULT hr=NULL;

hr = m_FtpCom->ListNames((_variant_t)sDir.AllocSysString());
if(!SUCCEEDED(hr))
return FALSE;

hr = m_FtpCom->get_ListItem(&bstrList);
if(!SUCCEEDED(hr))
return FALSE;

sFiles.Format(_T( s ),bstrList);

CString Sfile,Sdir;
int index1,index2;

while(sFiles.GetLength()!=0)
{
index1=sFiles.Find(_T( / ));
index2=sFiles.Find(_T(
));
if(index2<index1 || index1 == -1)
{//here u will get the filename
Sfile= sFiles.Left(index2-1);
sFiles=sFiles.Right(sFiles.GetLength()-index2-1);
sList = sList + Sfile + _T( , );
}
else
{//here u will get the directory name
Sdir= sFiles.Left(index2-1);
sFiles=sFiles.Right(sFiles.GetLength()-index2-1);
}

}
if(sList.GetLength()>0)
sList=sList.Left(sList.GetLength()-1);
//sList now contains the list of all the filenames[','
SEPARATED present in the given directory.
}

//USE THE ABOVE FUNCTION TO GET THE LIST OF FILENAMES
//set csFiles = sList

while(csFiles.GetLength()>0)
{
iIndex = csFiles.Find(_T( , ));
if(iIndex !=-1 )
{
sFname = csFiles.Left(iIndex);
csFiles = csFiles.Right(csFiles.GetLength()-iIndex-1);
}
else
{
sFname = csFiles;
csFiles=_T( );
}
//since u have the filename here use GetFile method
}//end of while loop

//at the end of this while loop u have all the files at the desired location


Regards
Sumeet


Complete thread: