File name verfication - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: File name verfication (/showthread.php?tid=1551) Pages:
1
2
|
File name verfication - NasaCow - 03-15-2023 So, was digging through the wiki and here. Hoping for a command, or a library but is there a simple way to verify input as a filename that won't crash a program with an illegal character? Thanks guys and gals RE: File name verfication - SMcNeill - 03-15-2023 INPUT "Give me a file name =>"; file$ IF _FILEEXISTS(file$) THEN PRINT "Found that file!" ELSE PRINT "File doesn't exist!" END IF ********************* If you're looking for a way to check to see if a name is valid, for saving purposes rather than loading, that's something you'd have to write yourself as per the ruleset of what's acceptable for you OS. (Windows is much pickier, for example, than Linux when it comes to valid file name characters.) RE: File name verfication - RhoSigma - 03-15-2023 This is my verification function, feel free to use it and/or adapt to your needs: Code: (Select All) LINE INPUT "Filename: "; f$ RE: File name verfication - mnrvovrfc - 03-15-2023 "Invalid" on Linux could include whatever ASCII code is less than 32. Could create a "fork bomb" with a control character. It's possible to put a newline as part of a filename which is sick. The "bash" command processor in particular is very fussy, one could pull his/her hair out trying to program a script toward a list of filenames containing CHR$(32) spaces, apostrophe (needed most of the time to precisely quote stuff), ampersand (one of them launches a process and keeps it going, two of them is like colon in BASIC), colon (path separator), dollar sign (preface environment variables and replaceable parameters), grave accent (needed to fire a second instance of "bash" to then use the "stdout" out of it) and stuff like that. A programmer might like to employ "bash" sometimes to see if a filename is "legal" on Linux. RE: File name verfication - NasaCow - 03-16-2023 (03-15-2023, 05:37 AM)SMcNeill Wrote: INPUT "Give me a file name =>"; file$ I take you up on your challenge and came up with this. Anyone is free to use said code! I tried to make it customizable for others as wll. Code: (Select All) OPTION _EXPLICIT Instead of what's not vaild, I tried to capture what is vaild and also ensure our file meets whatever restrictions that is set. I also included a limit and spaces to avoid stranger file names. (03-15-2023, 07:39 AM)RhoSigma Wrote: This is my verification function, feel free to use it and/or adapt to your needs: I like how short and simple this is! If I saw it before I made one, I might have just used this instead RE: File name verfication - SpriggsySpriggs - 03-16-2023 You can also do wide strings RE: File name verfication - mnrvovrfc - 03-16-2023 Code: (Select All) ISVALID` = TRUE 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. RE: File name verfication - Kernelpanic - 03-16-2023 Quote:@RhoSigma - This is my verification function, feel free to use it and/or adapt to your needs QB64 cannot read German umlauts or special characters in file names or folders. The program doesn't recognize them either. That is, for example the Übungen (Exercises) folder will not found. -- 132 = ä Code: (Select All) 'Ueberpruefung eines anzugebenen Dateinamens, RhoSigma - 16. Maerz 2023 This condition does not work, the program is aborted even if the name is correct. I put that after the FOR loop. Code: (Select All) If Asc(file) = 132 Or 142 Or 148 Or 151 Or 153 Or 154 Then RE: File name verfication - mnrvovrfc - 03-16-2023 That should be: Code: (Select All) Select Case Asc(file) Cannot transfer a "SELECT CASE" clause directly into an "IF" statement like that. This was a modification to the block you presented. I noticed above the line was "Asc(file, i)" so what you're actually doing is checking only the first character of string variable "file". It's not recommended to use strange characters in your filenames especially if it involves a program that will be shared with somebody else. RE: File name verfication - SpriggsySpriggs - 03-16-2023 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. |