'File source from Holyguard.net
'# 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
'===============================================================================
'# STRIPPATH : Returns file path (without file name)
FUNCTION StripPath (fullname AS STRING) AS STRING
result = LEFT$(fullname, rinstr(fullname, "\"))
END FUNCTION
'===============================================================================
'# STRIPFILENAME : Returns file name (without path)
FUNCTION StripFileName (fullname AS STRING) AS STRING
result = RIGHT$(fullname, LEN(fullname) - rinstr(fullname, "\"))
END FUNCTION
'===============================================================================
'# STRIPFILEEXT : Returns file extension (like ".exe", ".html" etc.)
FUNCTION StripFileExt (fullname AS STRING) AS STRING
result = RIGHT$(fullname, LEN(fullname) - rinstr(fullname, ".") + 1)
END FUNCTION
'===============================================================================
'# FILENAMENOEXT : Returns file name without extension
FUNCTION FileNameNoExt(fullname AS STRING) AS STRING
fullname = RIGHT$(fullname, LEN(fullname) - rinstr(fullname, "\"))
result = LEFT$(fullname, rinstr(fullname, ".") - 1)
END FUNCTION
'===============================================================================
'# FULLPATHNOEXT : Returns full path without file extension
FUNCTION FullPathNoExt(fullname AS STRING) AS STRING
result = LEFT$(fullname, rinstr(fullname, ".") - 1)
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
'===============================================================================
'# SYSDIR : Retrieves windows shell directories
'-------------------------|
' Allowed values for dir |
'-----------------------------------------------------------------------------|
' Desktop | Templates | AppData |
' Start Menu | Programs | Startup |
' Fonts | SendTo | Recent |
' Favorites | Cache | Cookies |
' History | NetHood | Personal |
' PrintHood | Local AppData | My Pictures |
' Administrative Tools | | |
'-----------------------------------------------------------------------------|
FUNCTION SysDir (dir AS STRING) AS STRING
DIM fo_reg AS QREGISTRY
fo_reg.RootKey = &H80000001
fo_reg.openkey ("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", 0)
result = fo_reg.readstring(dir) + "\"
END FUNCTION
'===============================================================================
'# HOMEDIR : The folder where the application is
FUNCTION homedir() AS STRING
result = LEFT$(COMMAND$(0), rinstr(COMMAND$(0), "\"))
END FUNCTION
'===============================================================================
'# BROWSEFORFOLDERS : Returns the selected folder
FUNCTION BrowseForFolders (initialdir AS STRING, wincapt AS STRING) AS STRING
DIM bff_form AS QFORM
WITH bff_form
.height = 400
.center
.caption = wincapt
.delbordericons 2
END WITH
DIM bff_tree AS QDIRTREE
WITH bff_tree
.parent = bff_form
.align = 5
END WITH
IF bff_form.caption = "" THEN bff_form.caption = "Select folder"
IF DIREXISTS(initialdir) THEN
bff_tree.directory = initialdir
ELSE
bff_tree.directory = CURDIR$
END IF
bff_form.showmodal
result = bff_tree.directory
END FUNCTION
'===============================================================================
'# BROWSEFORFILE : Returns the selected folder
FUNCTION BrowseForFile (caption AS STRING, filter AS STRING, _
initialdir AS STRING) AS STRING
DIM bff_od AS QOPENDIALOG
WITH bff_od
.caption = caption
.filter = filter
.initialdir = initialdir
IF .execute THEN
result = .filename
END IF
END WITH
END FUNCTION