'========================================================================
' Fileops is a set functions to manipulate file names and paths.         
' QUOTE - Returns a quoted string                                        
' GetPATH - Returns file path (without file name)                      
' GetFILENAME - Returns file name (without path)                        
' GetFILEEXT - Returns file extension (like ".exe", ".html" etc.)      
' GetFILENAMENOEXT - Returns file name without extension                   
' GetFULLPATHNOEXT - Returns full path without file extension              
' SetPATH - Set file path (with the same file name)                      
' SetFILENAME - Set file name (with the same file path)                        
' SetFILEEXT - Set file extension (with the same file path and name)      

'========================================================================

' QUOTE : Returns a quoted string 
function Quote (StringToQuote as string) as string
StringToQuote =  chr$(34) + StringToQuote + chr$(34)
result = replacesubstr$(stringtoquote, chr$(34) + chr$(34), chr$(34))
end function

'=============================================================================== 
' GetPATH : Returns file path (without file name) 
Function GetPath (fullname as string) as string
result = left$(fullname, rinstr(fullname, "\"))
end function

'=============================================================================== 
' GetFILENAME : Returns file name (without path) 
Function GetFileName (fullname as string) as string
result = right$(fullname, len(fullname) - rinstr(fullname, "\"))
end function

'=============================================================================== 
' GetFILEEXT : Returns file extension (like ".exe", ".html" etc.) 
Function GetFileExt (fullname as string) as string
result = right$(fullname, len(fullname) - rinstr(fullname, ".") + 1)
end function

'=============================================================================== 
' GetFILENAMENOEXT : Returns file name without extension 
function GetFileNameNoExt(fullname as string) as string
fullname = right$(fullname, len(fullname) - rinstr(fullname, "\"))
result = left$(fullname, rinstr(fullname, ".") - 1)
end function

'=============================================================================== 
' GetFULLPATHNOEXT : Returns full path without file extension 
function GetFullPathNoExt(fullname as string) as string
result = left$(fullname, rinstr(fullname, ".") - 1)
end function

'===============================================================================
'# SetPATH : Set file path (without file name)
Function SetPath (fullname as string, newPath as string) as long
if right$(newPath,1)<>"\" then newPath=newPath+"\"
fullname=newPath+getfilename(fullname)
end function

'===============================================================================
'# SetFILENAME : Set file name with old path
Function SetFileName (fullname as string, Newname as string) as integer
fullname=GetPath (fullname)+Newname
end function

'===============================================================================
'# SetFILEEXT : Set file extension
Function SetFileExt (fullname as string, Newext as string) as integer
fullname=GetFullPathNoExt(fullname)+Newext
end function

'===============================================================================
'# C_Style : Returns "slashed" path from a "backslashed" one
function C_Style (fullname as string) as string
fullname = replacesubstr$(fullname, "\\", "\")
result = replacesubstr$(fullname, "\", "/")
end function


'===============================================================================
FUNCTION FileSize(FileName as STRING ) AS integer
f = freefile
open FileName for input as #f
filesize=lof(f)
close #f
end function
'===============================================================================
function loadfromfile (fname as string, linetb() as string ) as integer '===============================================================================
FUNCTION LoadString(FName as STRING ) AS string

'===============================================================================
(Andrew Shelkovenko dec 2003)

'===============================================================================
sub MKSubDir (DirDst$)
'
Create DirDst$ directory with full subdir structure
Example:
MKSubDir ("C:\BAS\RAPIDQ\RQ_E140\old\RQDPhlp\
")

'===============================================================================
sub SubDirCopy (DirSrc$, DirDst$, mask$) 
'Copy DirSrc$ directory with full subdir structure and files (by mask$) to DirDst$
'===============================================================================
sub DirCopy (DirSrc$, DirDst$, mask$) 
'Copy files (by mask$) from DirSrc$ to DirDst$

'=============================================================================== 
sub KillFiles (FileName$) 
'Kill files in FileName$
'for example FileName$="C:\BAS\RAPIDQ\tmp\*.tmp"
FName$ = DIR$(FileName$, 0) '-- Get first file
while FName$ <>""
kill FName$
if fileexists (FName$)>0 then print "Can't kill file "+FName$
FName$ = DIR$ '-- Get next file
wend
end sub