Announcement

Collapse
No announcement yet.

Test for Valid File Name String

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Originally posted by Mike Doty View Post
    Important note if backslash is in file name
    The function (post #5), tested here, will fail if there is a \ in the file name because PathCleanupSpec considers backslash invalid.
    https://docs.microsoft.com/en-us/win...athcleanupspec
    Well, I wouldn't call that a fail, quite the opposite. That's a behaviour I personally would expect. If a file name includes a backslash, it's not a valid file name, hence the backslash gets removed.

    Comment


    • #22
      Knuth is correct the PathCleanupSpec function will remove, replace characters and report the result or error.

      Gary created a function to only see if name passed would be valid and return 0 or -1 using PathCleanupSpec that does not modify the passed string.
      https://duckduckgo.com instead of google

      Comment


      • #23
        I had some backup software years ago made by Core that used tapes.
        Yes, the people that made dependable hard drives.
        I remember some filenames being changed as it was stored on the tapes from the original file names
        I think it was the "at" @ character or the dollar sign $. It could have been both.
        p purvis

        Comment


        • #24
          VirtualStore
          Since this thread is about valid file names, just ran across virtualization and the UAC.
          This code writes to the virtual store based upon the user (not the C:\)
          Could cause some big problems with multiple users on the same machine.
          I try never to write to the root folder, but this could be used instead of the registry and using the full path might be safer.

          Code:
          'File placed into C:\Users\your_user_name\AppData\Local\VirtualStore
          FUNCTION PBMAIN () AS LONG
           LOCAL s AS STRING
           s = "\my settings"
           ? STR$(isValidFileName(s))
          END FUNCTION
          
          FUNCTION isValidFileName(s AS STRING) AS LONG
           LOCAL hFile AS LONG
           hFile = FREEFILE
           OPEN s FOR OUTPUT AS hFile
           IF ERR = 0 THEN FUNCTION = -1:CLOSE hFile 'do not kill so you can find the file with "Everything program"
          END FUNCTION
          
          'https://kb.photodex.com/8108/accessing-the-virtual-store-folder-in-windows-2/
          'https://stackoverflow.com/questions/14005081/how-to-detect-file-redirection-to-the-windows-virtualstore
          https://duckduckgo.com instead of google

          Comment


          • #25
            A little late to enter this discussion but, for what it is worth, the PB function IsFile catches all the reserved words COMx, LPTx, CON, AUX, PRN, NUL, etc. and reports that these files exist. Not as elegant as some of the other solutions put forward but can be used to report an invalid use of a reserved word for a file name.

            Comment

            Working...
            X