|
-
Jan 8th, 2008, 06:00 AM
#1
Thread Starter
PowerPoster
File information of the folder content.
Hi all,
I'm looking to read a folder which contain number of files. I want to get some details of those files, like Name, Size, Date Created. Those details I can see from the details view of the folder.
To start I try to find the file name as follows.
Try to find the paths of all files included in a folder as follows.
Code:
int CCountOne::SearchDirectory(vector &refvecFiles,const string &refcstrRootDirectory, const string &refcstrExtension, bool bSearchSubdirectories)
{
bSearchSubdirectories = true; // Handle the directories and subdirectories
string strFilePath; // Filepath
string strExtension;// Extension
string strPattern; // Pattern
HANDLE hFile; // File handler
WIN32_FIND_DATA FileInformation; // File information, use relevent structure of WinAPI
// Set the path pattern
strPattern = refcstrRootDirectory + "\\*.*";
hFile = ::FindFirstFile(strPattern.c_str(), &FileInformation);// Get the handler pointed
int iCount = 0;// Number of iterations
if(hFile != INVALID_HANDLE_VALUE)
{
do
{
if(FileInformation.cFileName[0] != '.')
{
strFilePath.erase();// Clear the exsisting path
strFilePath = refcstrRootDirectory + "\\" + FileInformation.cFileName;// Set the new path
if(FileInformation.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
{
if(bSearchSubdirectories)
{
// Search the subdirectories
int iRC = SearchDirectory(refvecFiles, strFilePath, refcstrExtension, bSearchSubdirectories);
if(iRC)
{
return iRC;
}
}
else
{
// Extension check
strExtension = FileInformation.cFileName;// Use the file name
strExtension = strExtension.substr(strExtension.rfind(".") + 1);
cout << strExtension << endl;
if(strExtension == refcstrExtension)
{
// Save the file name
refvecFiles.push_back(strFilePath);
}
}
}
else
{
cout << "Error_Two" << endl;
}
}
}while(::FindNextFile(hFile, &FileInformation) == TRUE);
// Close the handle
::FindClose(hFile);
DWORD dwError = ::GetLastError();
if(dwError != ERROR_NO_MORE_FILES)
{
return dwError;
}
}
return 0;
}
In this code set the folder path and start work.
Code:
void CCountOne::GetStart(void)
{
int iRC = 0;
vector vecSrfFiles;// bin file name
// Search "C:\Bin Files\Bin" for "*.srf" files
// Subdirectories also included
iRC = SearchDirectory(vecSrfFiles, "C:\\Bin Files\\Bin", "srf", true);
// Check the error
if(iRC != 0)
{
cout << "Error_One " << iRC << endl;
}
// Print the result
for(vector::iterator iterSrf = vecSrfFiles.begin(); iterSrf != vecSrfFiles.end(); ++iterSrf)
{
cout << *iterSrf << endl;
}
}
But it don't give any file path. Try to debug and check, seems
if(FileInformation.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
of code one stuck me with.
Can you guys just look at it.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|