How to resolve the algorithm Check that file exists step by step in the Liberty BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Check that file exists step by step in the Liberty BASIC programming language
Table of Contents
Problem Statement
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
Optional criteria (May 2015): verify it works with:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Check that file exists step by step in the Liberty BASIC programming language
Source code in the liberty programming language
'fileExists.bas - Show how to determine if a file exists
dim info$(10,10)
input "Type a file path (ie. c:\windows\somefile.txt)?"; fpath$
if fileExists(fpath$) then
print fpath$; " exists!"
else
print fpath$; " doesn't exist!"
end if
end
'return a true if the file in fullPath$ exists, else return false
function fileExists(fullPath$)
files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
fileExists = val(info$(0, 0)) > 0
end function
'return just the directory path from a full file path
function pathOnly$(fullPath$)
pathOnly$ = fullPath$
while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
wend
end function
'return just the filename from a full file path
function filenameOnly$(fullPath$)
pathLength = len(pathOnly$(fullPath$))
filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
You may also check:How to resolve the algorithm Memory layout of a data structure step by step in the Tcl programming language
You may also check:How to resolve the algorithm Multi-base primes step by step in the Raku programming language
You may also check:How to resolve the algorithm Largest int from concatenated ints step by step in the Prolog programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Erlang programming language
You may also check:How to resolve the algorithm Test integerness step by step in the Fortran programming language