Oxygen Basic

Programming => Problems & Solutions => Topic started by: chrisc on April 25, 2018, 04:08:15 AM

Title: need a function to determine whether a folder exist
Post by: chrisc on April 25, 2018, 04:08:15 AM
Hello

i need a function to determine whether a folder exist or a code example that uses
PathFileExists function

can someone help on this? appreciate all help
Title: Re: need a function to determine whether a folder exist
Post by: chrisc on April 25, 2018, 04:14:26 AM
in PB we have a function like this below, would need an O2 equivalent

Code: [Select]
'======================================
' check if folder exist
 FUNCTION FolderExists(BYVAL FolderSpec AS STRING) EXPORT AS LONG
 FUNCTION = %FALSE
 IF ISTRUE PathFileExists(BYVAL STRPTR(FolderSpec)) THEN
    FUNCTION = %TRUE
    EXIT FUNCTION

END IF
END FUNCTION
Title: Re: need a function to determine whether a folder exist
Post by: Charles Pegge on April 25, 2018, 06:17:32 AM
Hi Chris,

This page lists all the file management functions

https://msdn.microsoft.com/en-us/library/windows/desktop/aa364232(v=vs.85).aspx

I would suggest using FindFirstFile

Code: [Select]
uses corewin

function FileExists(char*fi) as int
===================================
WIN32_FIND_DATA fd
sys h
h=FindFirstFile fi,fd
if h>0 then
  FindClose h
  return 1
end if
end function

print FileExists("t.o2bas") 'file
print FileExists("ChrisC") 'folder

Title: Re: need a function to determine whether a folder exist
Post by: chrisc on April 25, 2018, 08:03:31 AM
Thanxx a lot Charles