Files command "error" when using correct file path

Discussions about the Liberty BASIC language, with particular reference to LB Booster
Tasp
Posts: 16
Joined: Sun May 31, 2020 4:51 pm

Files command "error" when using correct file path

Post by Tasp »

Took me a while to work this out, LB it will accept the DefaultDir as the main path, and any additional paths being added to the filter section LBB won't (ish). So thought I maybe able to save someone else sometime as I couldn't see any previous posts relating to it.

It would appear that you need to forgo the \ when using the FILES paths and filter, if your adding further paths to the filter.
LBB is strict when it means path$, that is all you can use. filter$ can only be the filename. LB is more forgiving and allows you to add path information to the filter area.
LBB is doing exactly what it says it will. path$ is the path$ and filter$ is the filter$.

See example below.

Code: Select all

'LBB helpfile
'FILES path$, [filter$,] array$()
'Fills array$() with a list of files and directories at path$, optionally specifying a filter (e.g. "*.bas").

DIM info(0,0)

PRINT DefaultDir$ + "\F1\F2\file.txt"

IF fileExists(DefaultDir$, "\F1\F2\file.txt") < 1 then
    NOTICE "Warning!" + chr$(13)+"file not found 1st try"
END IF

IF fileExists("", "\F1\F2\file.txt") < 1 then
    NOTICE "Warning!" + chr$(13)+"file not found 2nd try"
END IF

IF fileExists(DefaultDir$, "F1\F2\file.txt") < 1 then
    NOTICE "Warning!" + chr$(13)+"file not found 3rd try"
END IF

IF fileExists(DefaultDir$ + "\F1\F2\", "file.txt") < 1 then
    NOTICE "Warning!" + chr$(13)+"file not found 4th try"
END IF

END

FUNCTION fileExists(path$, filename$)
  FILES path$, filename$, info$()
  fileExists = val(info$(0, 0))  'non zero is true
  PRINT path$ + filename$, "Exists:"; fileExists
END FUNCTION

'include lb45func.bas