Jump to content

Unicode filesystem interaction without PHP6


fourrings

Recommended Posts

Is it possible and if so how?

 

I need to get a recursive filename listing of a directory that contains unicode filenames.  I've attempted piping scandir() output through php's iconv() with no luck.  This is for my desktop use so the platform is WinXP.  I've tried every trick possible and searched on dozens of forums with no luck.  Farthest I've gotten is being able to read and save contents from one utf-8 encoded file to another.  My fallback option is to render the list using DIR and then using php for processing, but sticking with php would be ideal.

Link to comment
Share on other sites

Whatever is native to XP's filesystem (NTFS), which I believe is indeed UTF16.  But I've not had os-specific issues using UTF8.

 

Try this... Едем На Море.  It will print in default CMD but will choke if you pipe it to a file, unless you include /u.

Link to comment
Share on other sites

Excerpts from win32\readdir.h and win32\readdir.c from the PHP 5.2.9 src released on php.net:

 

 

In the following example, dp is a DIR type which is defined as:

 

typedef struct {
HANDLE handle;				/* _findfirst/_findnext handle */
short offset;				/* offset into directory */
short finished;				/* 1 if there are not more files */
WIN32_FIND_DATA fileinfo;	/* from _findfirst/_findnext */
char *dir;					/* the dir we are reading */
struct dirent dent;			/* the dirent to return */
} DIR;

 

 

As you can see, with TCHAR as the type of the cFileName member (well, if you looked up the WIN32_FIND_DATA struct), it is possible for Unicode support to be in that structure, but _UNICODE and so on are never defined in the PHP source.

 

Also, the following code would not work with Unicode:

 

strlcpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME+1);

 

DIR.dent.d_name is a char array :(.

 

 

So, there is definitely no Unicode support for readdir on Windows.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.