Hello,
how to solve the problem with extended ascii file names (unicode) such as accented characters or with dieresis (German language) or symbols (Chinese language) or Korean language, files that windows can not open by reporting errors.
example: "c:\\mydir\\srçelik" generate error
thank you
open extended ascii filename (unicode)
Moderator: 2ffat
Re: open extended ascii filename (unicode)
Windows can handle such filenames just fine. If you are having errors, it is because of a bug in your own code. Please show the actual code you are having trouble with.
Remy Lebeau (TeamB)
Lebeau Software
Lebeau Software
Re: open extended ascii filename (unicode)
my mistake,
I'm creating a list of images through the command dir c:\mydir\*. jpg / s / b> mylist.txt and I did not think he could not handle unicode characters, as I said.
I'm leaving the dir command.
I'm creating a list of images through the command dir c:\mydir\*. jpg / s / b> mylist.txt and I did not think he could not handle unicode characters, as I said.
I'm leaving the dir command.
Re: open extended ascii filename (unicode)
Why are you using the command line for that, instead of using a FindFirst/Next() loop in code?mark_c wrote:I'm creating a list of images through the command dir c:\mydir\*. jpg / s / b> mylist.txt and I did not think he could not handle unicode characters, as I said.
Remy Lebeau (TeamB)
Lebeau Software
Lebeau Software
Re: open extended ascii filename (unicode)
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.
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);
}
Re: open extended ascii filename (unicode)
FindFirst/Next() work just fine with mapped drives.mark_c wrote: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.
Mapped drives are configured on a per-user basis. One user cannot access another user's drive mappings.mark_c wrote: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.
You are using the C runtime library's findfirst()/findnext() functions (note the lower-casing). I was referring to the RTL's FindFirst/FindNext() functions instead (note the camel-casing), for example:mark_c wrote: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
#include <System.SysUtils.hpp>
void TForm1::FindJpgFiles(String folder, TStrings *files, bool recursive)
{
folder = IncludeTrailingPathDelimiter(folder);
TSearchRec sr;
if (FindFirst(folder + _D("*.*"), faAnyFile, sr) == 0)
{
do
{
/* ignore special directories */
if ((sr.Name != _D(".")) && (sr.Name != _D("..")))
{
String path = folder + sr.Name;
if (sr.Attr & faDirectory)
{
if (recursive)
FindJpgFiles(path, files, true);
}
else
{
if (SameText(ExtractFileExt(sr.Name), _D(".jpg")))
{
if (files) files->Add(path);
StatusBar1->Panels->Items[2]->Text = _D("Research in progress....") + IntToStr(found++);
}
}
}
//Application->ProcessMessages();
Update();
}
while (FindNext(sr) == 0);
FindClose(sr);
}
}
Code: Select all
TStringList *files = new TStringList;
FindJpgFiles(_D("C:\\some folder\\"), files, true);
// use files as needed...
files->SaveToFile(_D("C:\\some other folder\\list.txt"));
delete files;
Remy Lebeau (TeamB)
Lebeau Software
Lebeau Software
Re: open extended ascii filename (unicode)
thanks Remy,
you are an excellent teacher
you are an excellent teacher