News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Missing _wopendir()

Started by mul, March 05, 2021, 07:12:48 AM

Previous topic - Next topic

mul

Hi all,

I am missing in the header file dirent.h the wchar_t version of the _opendir(const char *) function, such as _wopendir(const wchar_t *).

Did I miss something?

Thank you for help.

TimoVJL

opendir is only POSIX function, not C99 nor C11.
May the source be with you

mul

Hello TimoVJL,

Thanks for the answer.

It's a pity, because it would be a useful addition, as other functions for directory handling like _wgetcwd() or _wchdir() work very well.

I would use this function to change to the (german) Windows directory "Öffentliche Musik" (public music).

I know there are other solutions for this, it would just be the easiest and safest way.

John Z

Hi Mul,

Perhaps I misunderstand your statement :
Quote from: mul on March 05, 2021, 03:03:23 PM
It's a pity, because it would be a useful addition, as other functions for directory handling like _wgetcwd() or _wchdir() work very well.

I would use this function to change to the (german) Windows directory "Öffentliche Musik" (public music).
Pelles C does support _wchdir()  to change to a Unicode directory, and _wgetcwd()..  include <direct.h>
So if you are just looking to change directories to Windows directory "Öffentliche Musik" then _wchdir(const wchar_t *);
will work for you.

John Z

mul

Hello John,

thank you for this answer.
Maybe it is difficult for me to explain my problem.

Yes, I can change to a Unicode directory by _wchdir(). But if I will open this directory to read the entries in it, then only the function _opendir() is available. Not available is _wopendir().

Also I code:  _opendir(_getcwd()) to open a directory, this works fine.
But it is not possible to code: _wopendir(_wgetcwd()), because _wopendir() doesn't exist !!

Therefore it would be nice to have this missing function to complete the set of functions for Unicode directory handling.

mul

John Z

Hi Mul,

Thanks - I understand now what you are looking for with that function  :)
If it existed I'd probably have used it too. 

I used a workaround in a Windows GUI program, that might also work
in a Windows Console program although I've not tried it there. But it is
only for Windows so it may be of no help.  I use an "invisible" Dir box to
get Unicode directory listing for directories.  Definitely more overhead than
the function call - but sometimes you just gotta get it done anyway you can.

RetVal = DlgDirListW(hwndDlg,p_data,DirBox,Invisible,DDL_DIRECTORY);

Then I can process the list of directories as needed.


Regards,
John Z

Stefan Pendl

#6
Why not use the Windows API for getting the short, 8.3, path?
In general all foreign, not English, folder names are only junctions that point to the English folders since Windows 7, use "dir /a" in a command prompt.
If the code is not cross platform using system functions of the operating system API would be a good workaround until the functions for wide characters are available.
In addition you could use the regular findfirst, findnext, etc. functions.
---
Stefan

Proud member of the UltraDefrag Development Team

John Z

Thanks Stefan,

One issue with that approach is if you use, for instance, a recent directory list similar to a recent file list. The end user would be confused by the 8.3 which looks nothing like the non-English directory name.

John Z

Stefan Pendl

OK, so for display one could use the long path, which is already present, since we got the short path from it.
The best approach until Pelle has decided to implement the wide character functions, is to build wrappers on your own that mimic the missing functions, using the _wfindfirst64, _wfindnext64 and _findclose functions.
---
Stefan

Proud member of the UltraDefrag Development Team

TimoVJL

May the source be with you

mul

Thanks to all.

I think the reference to the _wfind... functions is the best solution for me.

mul

Pelle

IIRC, most _wsomething() functions had an implementation somewhere that was relevant to support (more or less, some years ago). I have never seen a _wopendir() function. Not a big deal to add, but I'm not sure how useful it is to add yet another non-standard function, especially since it's just a wrapper around findfirst*/findnext*.
/Pelle