cxong / tinydir

Lightweight, portable and easy to integrate C directory and file reader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Downloads & Videos folder not displaying - windows

nhurde opened this issue · comments

Hello I love this library , but I'm having issues with displaying my videos and downloads folder. I tried using a folder inside of them and it worked, but for some odd reason these folders are not displaying.

Any idea why?

Please note I built a wrapper class around TinyDir so that I can not have to call it often.

See http://pastebin.com/sS3UfDAw and http://pastebin.com/EwTEJsf6

commented

Please describe the problem, steps to reproduce, what you expect to see, what you are seeing instead.

In order to reproduce simply attempt to browse:
C:\Users\YourName\Downloads
C:\Users\YourName\Music
C:\Users\YourName\Videos

I'm not sure if this is because some files have many caps in their name or not. But when trying both examples it crashes[on non-sort] and simply shows nothnig[on-sort] for me.

Details of your operating system?
Is there any non-ascii characters in "YourName" or in the folders?
ATTENTION: The two examples in README.md doesn't support Unicode in Windows. If you define _UNICODE && UNICODE and try to read unicode path, unknown error would occur.

IT's as clean as it can be: "C:\Users\TheNathanH'

Windows 7?8?10? Or something else?

Windows 10.

So I changed from the tinydir_open_sorted to just tinydir_open and I can now see files. The main problem is that now I can not see certain files. Their names do not appeared to be long at all and since its only from "C:\Users\YourName\Videos" it should not be an issue for a file named "eVERYONEHASAPURPOSE‬_day1" would not display here...

What do you think?

Here is a screenshot of the problem. I made my own gui/ide and it uses tinydir to get the files in the directory for this. See http://i.imgur.com/mhj1c8c.png

Please note I built a wrapper class around TinyDir so that I can not have to call it often.

See http://pastebin.com/sS3UfDAw and http://pastebin.com/EwTEJsf6

commented

Does the problem still exist if you use only tinydir, e.g. random_access_sample? I can't find a problem on my end.

~~If tinydir detects some errors, both tinydir_open and tinydir_open_sorted will return -1.~~~
Try to comfirm that.

I've seen that you've edited your comments. You're using tinydir in some project. But what about removing all other things and just testing tinydir?
PS: If you want to support widechar in Windows, please refer to list_to_file.c in samples or refer to tinydir.h.

@cxong when doing the random access files, I do not get anything returned.

@lautis0503 when using open_sorted I do not get values. When using tinydir_open I get a -1 returned randomly for these files. Perhaps files with too many uppercases can cause an error?

commented

Since I can't reproduce this problem, I'll need your help investigating this. Here's some things to try:

  1. When tinydir_open (or any other tinydir function) returns -1, what is the error? You can find it via errno/strerror
  2. You can also step into tinydir with a debugger and find which line it's exiting from, and what the related variable values are. For example, if it exits from this line: https://github.com/cxong/tinydir/blob/master/tinydir.h#L247 find out what the value of path is.
  3. If random_access_sample also reproduces the problem, how are you invoking it? Provide the exact cli command
  4. Also provide the full output when you run dir C:\Users\YourName\Music etc.

@cxong

[1]I just tried sterror and it says no error happened
[2]The line it's exiting from is not from the open command but the tinydir_readfile() function. It does pull about half of the files, but I'm not sure why it's not pulling the rest of them in my videos folder.

[3]I did not use the random_access_sample one as the issue will be worst than the other ones. the exact path being "C:/Users/TheNathanH/Videos"

[4] The full path is "C:/Users/TheNathanH/Videos" Here is the exact result:

gpe_file_browser_issue_07172016

commented
  1. Where did you check strerror? It must be immediately after the function call that causes the error, otherwise the error can be overwritten. Please try one of the samples, e.g. iterate_sample or random_access_sample. Note that iterate_sample is missing error checking on tinydir_next.
  2. Which line is it exiting from? Line number please
  3. Please try random_access_sample. You can invoke it using random_access_sample.exe C:/Users/TheNathanH/Videos
  4. Please provide the full output of dir C:\Users\TheNathanH\Videos. You can do this by using Win + R > cmd > type dir C:\Users\TheNathanH\Videos

1 & 2] I added just the function I'm calling to pastebin see http://pastebin.com/V3TsDi1a . Line 27->30 is for reading each file essentially. record_error just writes to a file.
3]I believe I found the problem which is quite odd... And a solution to solve it may be even more odd...
4] Please see the image attached. Now based on the earlier screenshot it appears these random symbols are somehow hidden inside of the filename which I have no idea how they got there and no idea how to process it...

gpe_directory_content_videos_folder

commented

Have you tried random_access_sample? What is the output? Which line of code is tinydir exiting from? I don't mean which line in your code, I mean which line in tinydir itself. You can find out by stepping through it with a debugger. If you are using visual studio, set a breakpoint on the same line that the problematic tinydir call is on (select line, press F9), step in (F11), then run step by step (F10) until it runs into an error line (e.g. goto bail).

On investigation via Step into method this line:

" if (dir == NULL || path == NULL || _tinydir_strlen(path) == 0)" - Line 239 is stepped into...

stderrno is saying "ERROR: Error: No such file or directory "

commented

See if tinydir works after you #define UNICODE before #include "tinydir.h". I think tinydir is failing because the filename contains a unicode character that strlen incorrectly thinks is an empty string. See https://github.com/cxong/tinydir/blob/master/samples/list_to_file.c for an example.

I think I can look at modifying tinydir so that it simply skips over files with "empty" file names instead of bailing.

Hello I'm unable to compile when using the unicode example. I'm getting: " error: cannot convert 'const TCHAR* {aka const char_}' to 'const wchar_t_' for argument '1' to 'size_t wcslen(const wchar_t*)'"

So that's it. I've said that the two examples don't support widechar.
TCHAR should aka wchar_t if UNICODE defined. Try to define both UNICODE and _UNICODE before any #include.

This entire situation is very confusing. I've followed the instructions as asked and defined both of these before anything else in my main statement.

commented

You must define UNICODE and_UNICODE before the #include for tinydir. This means that if you are #includeing it in a header, the #defines must go before them in the header. It's not about the main statement, because it's something the preprocessor uses, and not a runtime effect.

When I include unicode I get this error:

"||=== Build: Release in Game_Pencil_Engine_IDE (compiler: SDL2 Compiler) ===|
C:\Users\TheNathanH\Documents\pawbyte\gpe_crossplatform\Game_Pencil_Engine_IDE\src\libs\tinydir.h||In function 'int tinydir_open(tinydir_dir*, const TCHAR*)':|
C:\Users\TheNathanH\Documents\pawbyte\gpe_crossplatform\Game_Pencil_Engine_IDE\src\libs\tinydir.h|239|error: cannot convert 'const TCHAR* {aka const char*}' to 'const wchar_t*' for argument '1' to 'size_t wcslen(const wchar_t*)'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
commented

It's possible that you included some Windows or C headers before defining UNICODE/_UNICODE. For this to work properly, those defines must be done before anything else (e.g. stdio.h, Windows.h). One way to do this easily is to add those defines to your compiler script.

This whole process seems to be a bit too unnatural for a simple plug and play library. Unicodes and the processing of them should be included in tinydir by default versus the natural use be made into a 3 day debugging process.

For now I'm going to use dirent and posix directly.

commented

That's an interesting idea; that tinydir should silently convert UTF-16 filenames to UTF-8. It will solve your problem but I'm not sure if it's a perfect solution for all cases - iirc Windows fopen/fstream functions can't handle UTF-8 filenames so it's not a problem tinydir can completely hide from the developer.

One thing tinydir could do is correctly read the file name, i.e. I think strlen is incorrect, it should copy the entire filename buffer across, and then leave it up to the developer to treat it as UTF-16.

In any case it seems that you'll run into this problem as long as you're dealing with unicode filenames under Windows. I don't think dirent will solve your problem.

Agree to cxong.

MultiByteToWideChar and WideCharToMultiByte can convert between UTF-16 and UTF-8 in Windows 2000+. But since Windows cannot handle UTF-8 strings, we use wchar_t (UTF-16) instead. There are no advantages to use UTF-8 within tinydir.

If you need to program some cross-platform projects, you must have a knowledge of the differences between Windows and Linux (or POSIX), which includes the unicode encoding problem. And do it yourself. Tinydir has nothing to do.

There is a dirent library for windows. (https://github.com/tronkko/dirent)
But we also need to process widechar manually.
This issue could be closed.

commented

I wanted to reproduce this problem but couldn't manage to produce a filename that causes this issue 😦

It's okay guys, I got my IDE to work with my own line of code. It took a few hours and "days of stress"; bu it's okay.