03-17-2023, 02:29 AM
(This post was last modified: 03-17-2023, 02:38 AM by NasaCow.
Edit Reason: Unix part about case stuff
)
(03-16-2023, 03:37 PM)mnrvovrfc Wrote:Code: (Select All)ISVALID` = TRUE
FOR LoopCounter = 1 TO LEN(FileName)
FOR LoopCounter1 = 1 TO NumberOfVaildCharacters
IF FileNameParts(LoopCounter) <> Legal(LoopCounter1) THEN ISVALID` = FALSE: EXIT FUNCTION
NEXT LoopCounter1
NEXT LoopCounter
Set the function return value and leave straight away, no need to check it and no need to "set the trap" at each character in the "FileName" to check. This was coded also for more consistency with the function body code that appears before this demonstration.
Also I suggest using a "FOR... NEXT" loop to initialize most of the Legal() array. Because you will have to include uppercase and lowercase letters to check on Linux and MacOS. Filenames on Unix and Unix-like operating systems are case sensitive.
I have to set the trap because in this case EVERY filename will faii. For example A <> B and thus you will exit out through the trap. If I check for illegal characters, it would work (and that's what my first try was) but then I have to think of everything. I decided to whitelist, instead of blacklisting. With whitelisting, I need to set a trap to check assuming it is a failed charater and switch to true when I find a whitelisted character..... Unless I am missing something else
And I am not as familiar with MacOS or Unix, but wouldn't the code still find it is vaild since I am converting everything to uppercase with UCASE$? I am not checking if a file exists, but if a given filename can be written to the system? _FILEEXISTS already is a great tool for that job. If not, I will be happy to add lower case to the search field.
(03-16-2023, 09:15 PM)Balderdash Wrote: If I can find my code then I'll send it. I was dealing with files with Korean, Chinese, and Japanese characters in the filename with no issues at all by just replicating FileExists but with wide string usage as well as using my AnsiToUnicode wrappers for converting between CP437 and UTF8 and vice-versa. The only issue you might have would be trying to display the name of the chosen file. I think you would also need to use the wide version of GetOpenFileName like I did. I was even able to replicate the drag and drop functions in QB64 as wide versions. I have no problem dropping any files with foreign characters in them.
I was wondering if you knew how to read input in Chinese from the keyboard, that would be very useful for me. I haven't been able to figure anything out. Displaying Chinese charaters is straight enough with QPrint (Uprint) with the proper font file that supports unicode. But I haven't been able to read anything from the keyboard... yet!