-- _file_.e
-- _file_.e
Following global procedures are defined:
replaces all occurences of a sub-string by another in a file
Params:text to be replaced
new text
result is written in a new file
old file is not affected
replace_text("test_file_.bak", "new_file_.bak", "this", "that")
writes a sequence of lines in a CSV file
Params:CSV separator is a semicolon
CSV strings are surrounded by quotes
write_csv("test2.csv", {{1,"Two",3,"Four"},{1,"Two",3,"Four"}})
analyze_object(read_csv("test2.csv", 1), "read_csv")
read_csv =
. [1]
. . [1] 1
. . [2] "Two"
. . [3] 3
. . [4] "Four"
appends a sequence of lines to a CSV file
Params:append_csv("test2.csv", {{1,"Two",3,"Four"},{1,"Two",3,"Four"}})
writes a sequence of lines in an INI file
Params:{ {section name, section content}, ... }
each section content is a list of parameters and values { "parameter=value", ... }
write_ini_file("test2.ini", {{"Section",{"name=value"}}})
[Section]
name=value
read_ini_file()
writes an element of an INI file
Params:INI file name
write_ini("test.ini", "Telnet", "port", "223")
[Telnet]
host=127.0.0.1
port=223
write_ini("test.ini", "HTTP", "host", "127.0.0.1")
[HTTP]
host=127.0.0.1
write_ini("test.ini", "HTTP", "port", "80")
[HTTP]
host=127.0.0.1
port=80
search_ini(), read_ini()
Following global functions are defined:
remove end of line characters from given sequence
Params:puts(1, remove_eol("First Line\nSecond Line\r\nThird Line\rFourth Line") & "\n")
First Line Second Line Third Line Fourth Line
splits a complete filename in drive, path, name and extension
Params:s = split_filename("C:\path\filename.txt")
s is:
. [1] "C"
. [2] "\path"
. [3] "filename"
. [4] "txt"
returns file drive
Params:s = file_drive("C:\path\filename.txt") --> "C"
file_path(), file_base(), file_ext(), file_name()
returns file path
Params:s = file_path("C:\path\filename.txt") --> "\path"
file_drive(), file_base(), file_ext(), file_name()
returns filename without extension or path
Params:s = file_base("C:\path\filename.txt") --> "filename"
file_drive(), file_path(), file_ext(), file_name()
returns file extension
Params:s = file_ext("C:\path\filename.txt") --> "txt"
file_drive(), file_path(), file_base(), file_name()
returns filename with extension, without path
Params:s = file_name("C:\path\filename.txt") --> "filename.txt"
file_drive(), file_path(), file_base(), file_ext()
Get the type of a file
Params:name of the file to query. It must not have wildcards.
integer:
* -1 if file could be multiply defined
* 0 if filename does not exist
* 1 if filename is a file
* 2 if filename is a directory
dir()
Returns the size of a file
Params:name of the file to search size of
atom: size of file if existing or -1 else
a = file_length("C:\\path\\filename")
returns file version
Params:name of the bound executable program
string: file version
Example:cmd = command_line()
s = get_file_version(cmd[1])
Determine if the supplied string is an absolute path or a relative path
Params:name of the file path
A relative path is one which is relative to the current directory and
an absolute path is one that doesn't need to know the current directory
to find the file.
integer: 0 if filename is a relative path or 1 otherwise
? is_absolute_path("") -- returns 0
? is_absolute_path("/usr/bin/abc") -- returns 1
? is_absolute_path("\\temp\\somefile.doc") -- returns 1
? is_absolute_path("../abc") -- returns 0
? is_absolute_path("local/abc.txt") -- returns 0
? is_absolute_path("abc.txt") -- returns 0
? is_absolute_path("c:..\\abc") -- returns 0
? is_absolute_path("c:\\windows\\system32\\abc") -- returns 1
? is_absolute_path("c:/windows/system32/abc") -- returns 1
Returns sum of all file sizes from rootdir and all subdirs
Params:directory to search size of
atom
a = dir_size("C:\\path\\subpath")
returns parent dir of given path
Params:remove last sub directory from path if there is one and return it.
if root return empty sequence
path has to point to a folder and not to a file
parent_dir(".") --> ".."
parent_dir("C:\path\subpath") --> "\path"
reads a CSV file in a sequence
Params:CSV file to read
if set skip first line in CSV file
CSV separator is a semicolon
CSV strings may be surrounded by quotes
analyze_object(read_csv("test.csv", 0), "read_csv")
read_csv =
. [1]
. . [1] "Name"
. . [2] "Bytes"
. . [3] "Size"
. . [4] "#Files"
. . [5] "Most recent"
. [2]
. . [1] "Z:\"
. . [2] 56144659864
. . [3] "52,29 GB"
. . [4] 23855
. . [5] 2016
. [3]
. . [1] "Z:" & SLASH & "BlackBox"
. . [2] 81699302
. . [3] "77,91 MB"
. . [4] 4
. . [5] 2012
. [4]
. . [1] "Z:" & SLASH & "Dying_Gasp"
. . [2] 7757074
. . [3] "7,40 MB"
. . [4] 66
. . [5] 2015
. [5]
. . [1] "Z:" & SLASH & "Temp"
. . [2] 812629032
. . [3] "774,98 MB"
. . [4] 641
. . [5] 2016
analyze_object(read_csv("test.csv", 1), "read_csv")
read_csv =
. [1]
. . [1] "Z:\"
. . [2] 56144659864
. . [3] "52,29 GB"
. . [4] 23855
. . [5] 2016
. [2]
. . [1] "Z:" & SLASH & "BlackBox"
. . [2] 81699302
. . [3] "77,91 MB"
. . [4] 4
. . [5] 2012
. [3]
. . [1] "Z:" & SLASH & "Dying_Gasp"
. . [2] 7757074
. . [3] "7,40 MB"
. . [4] 66
. . [5] 2015
. [4]
. . [1] "Z:" & SLASH & "Temp"
. . [2] 812629032
. . [3] "774,98 MB"
. . [4] 641
. . [5] 2016
converts a sequence to a CSV line
Params:CSV separator is a semicolon
CSV strings are surrounded by quotes
puts(1, sequence_to_csv({1,"Two",3,"Four"}) & "\n")
1;"Two";3;"Four"
find the index of a parameter in a list of strings "parameter=value"
Params:list of strings to search in
parameter name to search for
integer: requested index
sequence params
params = {"first=1","second=2","third=three"}
? find_param_name(params, "third")
3
set_param_value(), get_param_value()
find the value of a parameter in a list of strings "parameter=value"
Params:list of strings to search in
parameter name to search for
default value if not found. defaults to ""
sequence: requested value if found, default value if not
puts(1,get_param_value(params, "second") & "\n")
2
find_param_name(), set_param_value()
sets the value of a parameter in a list of strings "parameter=value"
Params:parameter name
parameter value
indicates to add value if not already existing. defaults to 1
if add is false (0), parameter value must exist to be modified
if add is true (1), a non-existing parameter will be added
sequence: modified list
sequence params
params = {"first=1","second=2","third=three"}
analyze_object(set_param_value(params, "third", "3"), "set_param_value")
set_param_value =
. [1] "first=1"
. [2] "second=2"
. [3] "third=3"
analyze_object(set_param_value(params, "fourth", "4", 0), "set_param_value")
set_param_value =
. [1] "first=1"
. [2] "second=2"
. [3] "third=three"
("add" is not set so parameter "fourth" is not added)
analyze_object(set_param_value(params, "fourth", "4"), "set_param_value")
set_param_value =
. [1] "first=1"
. [2] "second=2"
. [3] "third=three"
. [4] "fourth=4"
find_param_name(), get_param_value()
reads a file structured as an INI file
Params:result is a sequence { {section name, section content}, ... }
each section content is a list of parameters and values { "parameter=value", ... }
file test.ini contains following lines:
[Telnet]
host=127.0.0.1
port=23
[SSH]
host=127.0.0.1
port=22
[FTP]
host=127.0.0.1
port=21
analyze_object(read_ini_file("test.ini"), "read_ini")
read_ini =
. [1]
. . [1] "Telnet"
. . [2]
. . . [1] "host=127.0.0.1"
. . . [2] "port=23"
. [2]
. . [1] "SSH"
. . [2]
. . . [1] "host=127.0.0.1"
. . . [2] "port=22"
. [3]
. . [1] "FTP"
. . [2]
. . . [1] "host=127.0.0.1"
. . . [2] "port=21"
write_ini_file()
extracts a section from an INI file content
Params:INI file content
section name
file content has to be read previously with read_ini_file()
sequence: selected section content
ini = read_ini_file("test.ini")
s = get_ini_section(ini, "SSH")
s may be (example):
. [1] "host=127.0.0.1"
. [2] "port=22"
reads an element of an INI file
Params:INI file content
section of ini file to search in
key to search for
default value returned if search fails
file content has to be read previously with read_ini_file()
sequence: searched parameter value or default value if not found
puts(1, search_ini(ini, "FTP", "port") & "\n")
21
read_ini(), write_ini()
reads an element of an INI file
Params:INI file name
default value to return if read failed
puts(1, read_ini("test.ini", "Telnet", "port", -1) & "\n")
23
search_ini(), write_ini()