Just a quick question. Is it possible and what's the format for accessing sub-folders to delete files in A% with an XBasic script. For example, I have my main directory (at2 reports). It has a sub-folder called (input). I have other software that drops data to be converted into the "input" folder. Well, I have an autoexec script that automatically checks and appends the "input" data to my table. Now I am just trying to get A5 to automatically delete the files out of the directory after the append.
I had it working using this method:
'Deletes fonexxxx.txt from Input Directory
file.remove("input/fonexxxx.txt")
Now, the kicker is, I want it to delete out of the sub-folder, no matter WHERE I have the runtime installed. Basically, I don't want an absolute file path as there are several different machines and drive paths vary per machine. (In other words, I don't want c:\program files\at2reports\input).
Any thoughts? It was working and then it quit. (Or is this a bug?)
Thanks in advance!
Steve Hall
(Oh, and here is the full script)
'Date Created: 25-May-2005 11:53:40 AM
'Last Updated: 26-May-2005 12:46:55 PM
'Created By : Steve Hall
'Updated By : Steve Hall
'In case the destination table name is stored as a relative file name, or uses an alias
'in the drive/path specification, use the filename_decode() function to convert the
'filename to an absolute filename.
import_destination_table = filename_decode("fonexxxx.dbf")
import_filename = filename_decode("input\fonexxxx.txt")
if file.exists(import_filename) = .f. then
end
end if
ON ERROR GOTO ERROR25052005115312858
import.type = 0
import.names = "none"
import.file = import_filename
import.db = import_destination_table
import.skip_lines = 0
import.skip_bytes = 0
import.field_sep = ","
import.record_sep = ""CR""LF""
import.text_qualifier = ""
import.record_len = 81
import.rem_blanks = .F.
import.escape_newlines = .F.
import.fields = 14
import.field1 = "fileid,c,0,6,0"
import.field2 = "ani,c,1,12,0"
import.field3 = "dialeddigits,c,2,20,0"
import.field4 = "offhookdate,d,3,8,0"
import.field5 = "offhooktime,c,4,12,0"
import.field6 = "setupduration,n,5,5,0"
import.field7 = "callduration,n,6,8,0"
import.field8 = "destinationtype,c,7,6,0"
import.field9 = "paymenttype,c,8,6,0"
import.field10 = "amountcollected,n,9,6,0"
import.field11 = "totalprice,n,10,6,0"
import.field12 = "releaseindex,c,11,4,0"
import.field13 = "recordtype,c,12,255,0"
import.field14 = "flags,c,13,7,0"
import()
GOTO CONTINUE25052005115312858
ERROR25052005115312858:
ON ERROR GOTO 0
ui_msg_box("Error","Error running Import Operation"+crlf()+error_text_get())
END
CONTINUE25052005115312858:
'Add the import destination table to the database....
file_add_to_db(table.filename_get(import_destination_table))
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
DIM Append as P
a_tbl = table.open("cdr")
append.t_db = "fonexxxx"
ON ERROR GOTO ERROR25052005115329982
append.m_key = "ANI-cdate(OFFHOOKDATE)-OFFHOOKTIME"
append.t_key = "ANI-cdate(OFFHOOKDATE)-OFFHOOKTIME"
append.m_filter = ""
append.t_filter = ""
append.type = "Unique only"
append.m_count = 14
append.m_field1 = "Fileid"
append.m_exp1 = "@Fonexxxx-"Fileid"
append.m_field2 = "Ani"
append.m_exp2 = "@Fonexxxx-"Ani"
append.m_field3 = "Dialeddigits"
append.m_exp3 = "@Fonexxxx-"Dialeddigits"
append.m_field4 = "Offhookdate"
append.m_exp4 = "@Fonexxxx-"Offhookdate"
append.m_field5 = "Offhooktime"
append.m_exp5 = "@Fonexxxx-"Offhooktime"
append.m_field6 = "Setupduration"
append.m_exp6 = "@Fonexxxx-"Setupduration"
append.m_field7 = "Callduration"
append.m_exp7 = "@Fonexxxx-"Callduration"
append.m_field8 = "Destinationtype"
append.m_exp8 = "@Fonexxxx-"Destinationtype"
append.m_field9 = "Paymenttype"
append.m_exp9 = "@Fonexxxx-"Paymenttype"
append.m_field10 = "Amountcollected"
append.m_exp10 = "@Fonexxxx-"Amountcollected"
append.m_field11 = "Totalprice"
append.m_exp11 = "@Fonexxxx-"Totalprice"
append.m_field12 = "Releaseindex"
append.m_exp12 = "@Fonexxxx-"Releaseindex"
append.m_field13 = "Recordtype"
append.m_exp13 = "@Fonexxxx-"Recordtype"
append.m_field14 = "Flags"
append.m_exp14 = "@Fonexxxx-"Flags"
append.t_count = 0
a_tbl.append()
GOTO CONTINUE25052005115329982
ERROR25052005115329982:
ON ERROR GOTO 0
ui_msg_box("Error","Error running Append Operation"+crlf()+error_text_get())
END
CONTINUE25052005115329982:
a_tbl.close()
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
'Drops fonexxxx.dbf out of database
FILE_DROP_FROM_DB("fonexxxx.dbf")
'Deletes fonexxxx.dbf out of disk
table.erase("fonexxxx.dbf", .T.)
'Deletes fonexxxx.txt from Input Directory
file.remove("input/fonexxxx.txt")
I had it working using this method:
'Deletes fonexxxx.txt from Input Directory
file.remove("input/fonexxxx.txt")
Now, the kicker is, I want it to delete out of the sub-folder, no matter WHERE I have the runtime installed. Basically, I don't want an absolute file path as there are several different machines and drive paths vary per machine. (In other words, I don't want c:\program files\at2reports\input).
Any thoughts? It was working and then it quit. (Or is this a bug?)
Thanks in advance!
Steve Hall
(Oh, and here is the full script)
'Date Created: 25-May-2005 11:53:40 AM
'Last Updated: 26-May-2005 12:46:55 PM
'Created By : Steve Hall
'Updated By : Steve Hall
'In case the destination table name is stored as a relative file name, or uses an alias
'in the drive/path specification, use the filename_decode() function to convert the
'filename to an absolute filename.
import_destination_table = filename_decode("fonexxxx.dbf")
import_filename = filename_decode("input\fonexxxx.txt")
if file.exists(import_filename) = .f. then
end
end if
ON ERROR GOTO ERROR25052005115312858
import.type = 0
import.names = "none"
import.file = import_filename
import.db = import_destination_table
import.skip_lines = 0
import.skip_bytes = 0
import.field_sep = ","
import.record_sep = ""CR""LF""
import.text_qualifier = ""
import.record_len = 81
import.rem_blanks = .F.
import.escape_newlines = .F.
import.fields = 14
import.field1 = "fileid,c,0,6,0"
import.field2 = "ani,c,1,12,0"
import.field3 = "dialeddigits,c,2,20,0"
import.field4 = "offhookdate,d,3,8,0"
import.field5 = "offhooktime,c,4,12,0"
import.field6 = "setupduration,n,5,5,0"
import.field7 = "callduration,n,6,8,0"
import.field8 = "destinationtype,c,7,6,0"
import.field9 = "paymenttype,c,8,6,0"
import.field10 = "amountcollected,n,9,6,0"
import.field11 = "totalprice,n,10,6,0"
import.field12 = "releaseindex,c,11,4,0"
import.field13 = "recordtype,c,12,255,0"
import.field14 = "flags,c,13,7,0"
import()
GOTO CONTINUE25052005115312858
ERROR25052005115312858:
ON ERROR GOTO 0
ui_msg_box("Error","Error running Import Operation"+crlf()+error_text_get())
END
CONTINUE25052005115312858:
'Add the import destination table to the database....
file_add_to_db(table.filename_get(import_destination_table))
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
DIM Append as P
a_tbl = table.open("cdr")
append.t_db = "fonexxxx"
ON ERROR GOTO ERROR25052005115329982
append.m_key = "ANI-cdate(OFFHOOKDATE)-OFFHOOKTIME"
append.t_key = "ANI-cdate(OFFHOOKDATE)-OFFHOOKTIME"
append.m_filter = ""
append.t_filter = ""
append.type = "Unique only"
append.m_count = 14
append.m_field1 = "Fileid"
append.m_exp1 = "@Fonexxxx-"Fileid"
append.m_field2 = "Ani"
append.m_exp2 = "@Fonexxxx-"Ani"
append.m_field3 = "Dialeddigits"
append.m_exp3 = "@Fonexxxx-"Dialeddigits"
append.m_field4 = "Offhookdate"
append.m_exp4 = "@Fonexxxx-"Offhookdate"
append.m_field5 = "Offhooktime"
append.m_exp5 = "@Fonexxxx-"Offhooktime"
append.m_field6 = "Setupduration"
append.m_exp6 = "@Fonexxxx-"Setupduration"
append.m_field7 = "Callduration"
append.m_exp7 = "@Fonexxxx-"Callduration"
append.m_field8 = "Destinationtype"
append.m_exp8 = "@Fonexxxx-"Destinationtype"
append.m_field9 = "Paymenttype"
append.m_exp9 = "@Fonexxxx-"Paymenttype"
append.m_field10 = "Amountcollected"
append.m_exp10 = "@Fonexxxx-"Amountcollected"
append.m_field11 = "Totalprice"
append.m_exp11 = "@Fonexxxx-"Totalprice"
append.m_field12 = "Releaseindex"
append.m_exp12 = "@Fonexxxx-"Releaseindex"
append.m_field13 = "Recordtype"
append.m_exp13 = "@Fonexxxx-"Recordtype"
append.m_field14 = "Flags"
append.m_exp14 = "@Fonexxxx-"Flags"
append.t_count = 0
a_tbl.append()
GOTO CONTINUE25052005115329982
ERROR25052005115329982:
ON ERROR GOTO 0
ui_msg_box("Error","Error running Append Operation"+crlf()+error_text_get())
END
CONTINUE25052005115329982:
a_tbl.close()
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
'Drops fonexxxx.dbf out of database
FILE_DROP_FROM_DB("fonexxxx.dbf")
'Deletes fonexxxx.dbf out of disk
table.erase("fonexxxx.dbf", .T.)
'Deletes fonexxxx.txt from Input Directory
file.remove("input/fonexxxx.txt")
Comment