Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with FindFirstFile

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I have this:

MaxCuts = 5;
WIN32_FIND_DATA fname;
bool found = true;
HANDLE hfile = FindFirstFile((directory + "*").c_str(), &fname);
if (!SetCurrentDirectory(directory.c_str()))
{
WriteToLog("Unable to access " + directory);
return;
}
String filename;
int error;
TStringList* list = new TStringList;
if (hfile != INVALID_HANDLE_VALUE)
{
do
{
AnsiString s = (AnsiString)fname.cFileName;
if (fname.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (s != "." && s!= "..")
{
ShowMessage(directory + s + "\\");
}
}
else
{
ShowMessage("I am here");
filename = fname.cFileName;
ShowMessage(filename);
list->Add(filename);
}
}
while(FindNextFile(hfile, &fname));
FindClose(hfile);
}


directory is set to C:\incoming and I have 8 files in it that look like this:

12345678.123 (sample filename)

Why is it when I ShowMessage(s), I get incoming as the filename and not 12345678.123?

Thanks

Mindy
 
I haven't dug too deeply into your code but it runs in my mind that I had a similar problem when I used "filename" for my variable. Try to use a different variable than "filename."
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
I figured it out. I wasn't adding the trailing backslash to the directory path and therefore I was getting the same as a filename.

All fixed.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top