! Main for OpenFile, SpiltPathqq, FindFileqq

Program FileOps
use dfwin
use dflib

implicit none

! Define types for structure "ofn"
!character*(*),parameter :: filter_spec ='*.*'C
character(max_path) :: file_spec = ""C
character(max_path) lpstrInitialDir ,lpstrFilter, lpstrTitle, &
					lpstrDefExt, lpstrFile
integer nFilterIndex
character(max_path) CurrentDirectory; integer istat
integer SelectFile, status
integer lenCurr

integer l1

! SpiltPathqq:
character(3) drive
character(256) dir, name
character(4) ext
integer is

! FullPathqq:
character($maxpath) full_path

! Result file:
character($maxpath) Result_File, Result_Name*100


lpstrInitialDir =""C	!NULL
lpstrFilter = &
  "Data Files (*.dat)"C//"*.dat"C// &
  "Text Files (*.txt)"C//"*.txt"C//&
  "Fortran Files"C//"*.f90;*.f"C//&
  "All files (*.*)"C//"*.*"C//""C
lpstrTitle ='Select File'C
nFilterIndex =1
lpstrDefExt ='dat'C
lpstrFile ="*.dat"C	!""C


write(*, '(a, \)') 'Introdu nume fisier de rezultate (fara extensie): '
read(*, '(a)') Result_Name

Result_File =trim(Result_Name)//'.rez'

open(1, file =Result_File, status ='unknown', form ='formatted')


istat =GetCurrentDirectory(max_path, CurrentDirectory)
if(istat >0) then
lpstrInitialDir =CurrentDirectory
endif

status =SelectFile(lpstrInitialDir ,lpstrFilter, lpstrTitle, nFilterIndex, &
					lpstrDefExt, lpstrFile)

if(status >0) then

l1 =lstrlen(lpstrFile)
write(1, '(a, a)') 'Selected File: ', lpstrFile(:l1)

! get current directory
istat =GetCurrentDirectory(max_path, CurrentDirectory)
lenCurr =index(CurrentDirectory, char(0))
print '(/, a, a)', 'Current Directory is: ', CurrentDirectory(:lenCurr-1)

is =splitpathqq(lpstrFile, drive, dir, name, ext)

write(1, '(/, a, a)') 'drive: ', drive
write(1, '(a, a)') 'dir: ', dir(:is)
write(1, '(a, a)') 'name: ', trim(name)
write(1, '(a, a)') 'ext: ', ext

else
print*, 'Error / Canceled'
end if


is =FullPathqq(name, full_path)

write(1, '(/, a, a)') 'Path from FULAPTHQQ: ', trim(full_path)

write(*, '(/, a, a)') 'Fisier de Rezultate: ', trim(Result_File)

is =FindFileqq('Openfile.f90', 'f90', full_path)

write(1, '(/, a, I3)') 'File Length: ', is
write(1, '(a, a)') 'Path from FINDFILEQQ: ', trim(full_path)



END Program FileOps
