locked
invalid path or file name vfp error RRS feed

  • Question

  • Hi all,

     I am getting the error 'Invalid path or file name' (error no 202) in visual fox pro. Can anybody tell me what cause for the invalid file or path ?

    That means what is 'Invalid' here? I think if the file is not available it gives different error message.  Please help

    Thursday, May 10, 2012 4:24 PM

Answers

  • Hi,

    usually you get this error when you store your path/filename in a variable and there is a blank in the string.

    VFP reads the string up to the blank and tries to access the file or change to this directory and as neither exists, you get an error.

    To avoid this problem you should make use of name expressions:

    * // instead of
    lcTargetPath = [D:\My Files\My Pictures\]
    CHDIR &lcTargetPath
    
    * // or even worse
    lcTargetPath = [D:\My Files\My Pictures\]
    CHDIR "&lcTargetPath"
    
    * // you should do it like this
    lcTargetPath = [D:\My Files\My Pictures\]
    CHDIR ( lcTargetPath )
    
    * // and this can be done here, too
    SET ... TO ( lcFileName )
    USE ( lcTableName ) ALIAS ( lcAlias )
    CREATE TABLE/CURSOR ( lcCursorName )
    SELECT * FROM ( lcSourceTable ) INTO CURSOR/TABLE ( lcTargetCursor )
    SET PRINTER TO ( lcPrinterName )
    DIRECTORY( lcCheckIfPathExists )
    OPEN DATABASE ( lcDBCName )


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011


    • Proposed as answer by Pavel Celba Thursday, May 10, 2012 8:32 PM
    • Edited by Tom BorgmannEditor Friday, May 11, 2012 6:02 AM renamed forgotten variable
    • Marked as answer by Mark Liu-lxf Monday, May 21, 2012 9:46 AM
    Thursday, May 10, 2012 6:36 PM
    Answerer

All replies

  • Hi,

    usually you get this error when you store your path/filename in a variable and there is a blank in the string.

    VFP reads the string up to the blank and tries to access the file or change to this directory and as neither exists, you get an error.

    To avoid this problem you should make use of name expressions:

    * // instead of
    lcTargetPath = [D:\My Files\My Pictures\]
    CHDIR &lcTargetPath
    
    * // or even worse
    lcTargetPath = [D:\My Files\My Pictures\]
    CHDIR "&lcTargetPath"
    
    * // you should do it like this
    lcTargetPath = [D:\My Files\My Pictures\]
    CHDIR ( lcTargetPath )
    
    * // and this can be done here, too
    SET ... TO ( lcFileName )
    USE ( lcTableName ) ALIAS ( lcAlias )
    CREATE TABLE/CURSOR ( lcCursorName )
    SELECT * FROM ( lcSourceTable ) INTO CURSOR/TABLE ( lcTargetCursor )
    SET PRINTER TO ( lcPrinterName )
    DIRECTORY( lcCheckIfPathExists )
    OPEN DATABASE ( lcDBCName )


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011


    • Proposed as answer by Pavel Celba Thursday, May 10, 2012 8:32 PM
    • Edited by Tom BorgmannEditor Friday, May 11, 2012 6:02 AM renamed forgotten variable
    • Marked as answer by Mark Liu-lxf Monday, May 21, 2012 9:46 AM
    Thursday, May 10, 2012 6:36 PM
    Answerer
  • Tom provided a good answer, but do you know the source of the code throwing this error? If it's in the particular code, then Tom's  answer is the answer. Otherwise I'm thinking it may be a different kind of error and it's related to the invalid entries in the Path environmental variable.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Thursday, May 10, 2012 8:36 PM