3.1.1.9 Algorithm for Determining Path Type

The input for this algorithm is:

  • PathName: A null-terminated UTF-16 string that specifies the path name to check in a case-insensitive manner.

The output for this algorithm is:

  • Type: A path type value as specified in section 2.2.2.9 if the algorithm finds an appropriate path type; otherwise ERROR_INVALID_NAME (0x0000007B).

The pseudo code for the algorithm is shown in the following example.

  
 // The following set of characters MUST be treated as invalid characters: <> " |
 If (PathName contains invalid character)
 Return ERROR_INVALID_NAME;
       If (PathName begins with ‘\’)
          If (PathName begins with "\\’’)
           If (PathName begins with "\\.’’)
             If (PathName begins with "\\.\’’)
              If (Remaining part of the PathName contains ‘*’ or ‘?’)
       Return Type= ITYPE_PATH_ABSD_WC;
              Else
       Return Type= ITYPE_PATH_ABSD;
              EndIf
           Else
             Return ERROR_INVALID_NAME;
           EndIf
        ElseIf ((PathName begins with "\\<computer-name>’’)   
  // <computer-name> is any string other than ".")
          If (PathName begins with "\\<computer-name>\’’)
            If (Remaining part of the PathName is not empty)
     If (Remaining part of the PathName contains ’*’ or ‘?’)
               Return Type= ITYPE_UNC_WC_PATH;
     Else
          Return Type= ITYPE_UNC;
     EndIf
      EndIf
     Else
      Return Type= ITYPE_UNC_COMPNAME;
      EndIf
     ElseIf ((PathName begins with "\\*’)   
     If (PathName equals to "\\*’’)
      Return Type= ITYPE_UNC_WC;
     Else
         Return ERROR_INVALID_NAME;
       EndIf
     EndIf
  Else      // PathName begins with only single slash "\"
    If (PathName begins with "\DEV’’)   
      If (PathName equals "\DEV\LPT<n>’’ or "\DEV\LPT<n>:’’)
      // <n> is any number, Examples: "\DEV\LPT1", "\DEV\LPT4:"
      Return Type= ITYPE_DEVICE_LPT;
    ElseIf (PathName equals "\DEV\COM<n>’’ or "\DEV\COM<n>:’’)
    // <n> is any number, Examples: "\DEV\COM1", "\DEV\COM4:"
      Return Type= ITYPE_DEVICE_COM;
    Else 
      Return ERROR_INVALID_NAME;
    EndIf
  ElseIf (PathName contains ’*’ or ‘?’)
       Return Type= ITYPE_PATH_ABSND_WC;
  Else
       Return Type= ITYPE_PATH_ABSND;
      EndIf
   EndIf
 ElseIf (PathName begins with [A-Z] followed by ‘:’)// Examples: "C:", "f:"
   If (PathName equals "<drive>:")   // <drive> is any letter
     Return ITYPE_DEVICE_DISK
   Else // (PathName = "<drive>:\...")
    If (Remaining part of the PathName after "<drive>:"contains ’*’ or ‘?’)
      Return Type= ITYPE_PATH_ABSD_WC;
    Else
     Return Type= ITYPE_PATH_ABSD;
    EndIf
  EndIf
 ElseIf (PathName equals "LPT<n>" or "LPT<n>:")  //Examples: "LPT1", "lpt4:"
      Return Type= ITYPE_DEVICE_LPT;
 ElseIf (PathName equals "COM<n>" or "COM<n>:") //Examples: "COM1", "com4:"
 Return Type= ITYPE_DEVICE_COM;
 Else // Relative Paths
    If (PathName contains ’*’ or ‘?’)
       Return Type= ITYPE_PATH_RELND_WC;
    Else
         Return Type= ITYPE_PATH_RELND;
    EndIf
 EndIf