Remy, you caught me.
I used the dir command for a strangeness that had happened to me and that only today I solved. I tried using FindFirst / Next () but I could not access mapped network drives, I could only do this if I used the UNC path and I did not understand why.
Unfortunately, using the UNC paths I got too long paths and in some cases I got the "too long path" error.
Going deeper into the question, I found that windows behaves differently if the compiler runs as a normal user or as an administrator, in practice, the problem was due to a policy problem.
In practice: I ran the compiler as an administrator but I mapped the units as users and for this reason the administrator did not see the mapped disks; strange but it is so.
Fixed this problem, I left the dir command that causes the problem of non-ascii characters (Chinese) and I started using FindFirst / Next (), a version a little dated but that works.
- Code: Select all
void TForm1::FindMyFile(char *s)
{
struct ffblk ffblk;
char temp[MAXPATH]="";
int done;
TCHAR szBuf[MAX_PATH];
strcpy(temp, s);
strcat(temp, "*.*");
done=findfirst(temp,&ffblk,_A_SUBDIR | _A_RDONLY | _A_HIDDEN |_A_SYSTEM);
FILE *fp;
fp=fopen("list.txt","a+");
while(!done)
{
/* ignore special directories */
if (strcmp(ffblk.ff_name, ".") && strcmp(ffblk.ff_name, ".."))
{
if (ffblk.ff_attrib & _A_SUBDIR)
{
strcpy(temp, s);
strcat(temp, ffblk.ff_name);
strcat(temp, "\\");
FindMyFile(temp);
}
else
{
AnsiString path=String(s) + String(ffblk.ff_name);
if(fp && (strstr(path.c_str(),".jpg") != 0 ||
strstr(path.c_str(),".JPG") != 0)
)
{
fprintf(fp,"%s\n", path.c_str());
StatusBar1->Panels->Items[2]->Text="Research in progress...." + IntToStr(found++);
}
}
}
done = findnext(&ffblk);
Application->ProcessMessages();
}
fclose(fp);
}