Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Import and relative file delete

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Import and relative file delete

    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")
    Steve Hall

    #2
    RE: Import and relative file delete

    Windows uses the backslash character (\) for directory separators but your code is using a forward slash (/)

    You should try changing it to

    file.remove("input\fonexxxx.txt")

    Lenny Forziati
    Vice President, Internet Products and Technical Services
    Alpha Software Corporation

    Comment


      #3
      RE: Import and relative file delete

      I tried the slash both ways and it still isn't finding the file or subfolder. I have definately checked to see if the spelling and the files/folder exist and they do. It imports just fine, but it's the file delete that isn't working. It worked just fine last week and then it quit.
      Steve Hall

      Comment


        #4
        RE: Import and relative file delete

        If your text file to be deleted always resides in the same directory under the database directory, I would use a5,get_path() as in

        file.remove(a5.get_path()+chr(92)+"input\fonexxxx.txt")
        There can be only one.

        Comment


          #5
          RE: Import and relative file delete

          That worked! Thanks a bunch!

          Still Learning this

          Steve Hall
          Steve Hall

          Comment


            #6
            RE: Import and relative file delete

            A brief "educational moment":


            Actually, you don't need the "chr(92)" unless it is preceeded and followed by a variable. Otherwise, it's perfectly acceptable but not necessary.


            file.remove(a5.get_path()+"\input\fonexxxx.txt")

            will also work.


            However, if the ending character in the string needs to be a backslash then it must be changed to two backslashes because the backslash is the "escape character" that tells A5 to treat certain special characters following it as part of the text string itself. (Quotes and backslashes are the only "certain special characters" I know of but there may be others.) Therefore, in a case like this - "input\", A5 tries to treat the second quote as part of the string rather than the end of the string. The solution is two backslashes - "input\\" - in this case, the first backslash tells A5 to treat the second backslash as part of the string then the final quote stands by itself to define the end of the string.


            Now, if you create a variable to store the path and/or file name, you may need to use the chr(92) depending on how the variable is defined:

            fpath = "\input\fonexxxx.txt"

            file.remove(a5.get_path()+fpath) - no "chr()" req'd

            or it could be selected from a list with the intermediate folder as a fixed value that already includes the backslashes:

            DIM fname[3] as C

            fname[1] = "fonexxxx.txt"

            fname[2] = "foneyyyy.txt"

            fname[3] = "fonezzzz.txt"

            fselected = ui_get_list("TITLE", 1, "fname" )

            file.remove( a5.get_path() + "\input\\" + fselected ) - no "chr()" req'd

            but if it is selected from a list with no preceeding backslash and it is in the main folder:

            DIM fname[3] as C

            fname[1] = "fonexxxx.txt"

            fname[2] = "foneyyyy.txt"

            fname[3] = "fonezzzz.txt"

            fselected = ui_get_list("TITLE", 1, "fname" )

            file.remove( a5.get_path() + chr(92) + fselected )


            And, now that I think about it, it seems that chr(92) may never be required because another option should be to change the last line above to:

            file.remove( a5.get_path() + "\\" + fselected )

            I haven't tried this last idea in a working app but I just tested this in the interactive editor and it worked just fine:

            ui_msg_box( "TEST", "filename" + "\\" + "test.dbf" )


            Training session complete. Hope it will be useful. And I learned something, too. (I've heard that teachers often learn more than their students. Maybe it's true?!)


            Cal Locklin

            www.aimsdc.net

            Comment


              #7
              RE: Import and relative file delete

              Dang, missed a closing font tag. Sorry about that. This should be easier to read: (I hope!)

              A brief "educational moment":

              Actually, you don't need the "chr(92)" unless it is preceeded and followed by a variable. Otherwise, it's perfectly acceptable but not necessary.

              file.remove(a5.get_path()+"\input\fonexxxx.txt")
              will also work.

              However, if the ending character in the string needs to be a backslash then it must be changed to two backslashes because the backslash is the "escape character" that tells A5 to treat certain special characters following it as part of the text string itself. (Quotes and backslashes are the only "certain special characters" I know of but there may be others.) Therefore, in a case like this - "input\", A5 tries to treat the second quote as part of the string rather than the end of the string. The solution is two backslashes - "input\\" - in this case, the first backslash tells A5 to treat the second backslash as part of the string then the final quote stands by itself to define the end of the string.

              Now, if you create a variable to store the path and/or file name, you may need to use the chr(92) depending on how the variable is defined:
              fpath = "\input\fonexxxx.txt"
              file.remove(a5.get_path()+fpath) - no "chr()" req'd
              or it could be selected from a list with the intermediate folder as a fixed value that already includes the backslashes:
              DIM fname[3] as C
              fname[1] = "fonexxxx.txt"
              fname[2] = "foneyyyy.txt"
              fname[3] = "fonezzzz.txt"
              fselected = ui_get_list("TITLE", 1, "fname" )
              file.remove( a5.get_path() + "\input\\" + fselected ) - no "chr()" req'd
              but if it is selected from a list with no preceeding backslash and it is in the main folder:
              DIM fname[3] as C
              fname[1] = "fonexxxx.txt"
              fname[2] = "foneyyyy.txt"
              fname[3] = "fonezzzz.txt"
              fselected = ui_get_list("TITLE", 1, "fname" )
              file.remove( a5.get_path() + chr(92) + fselected )

              And, now that I think about it, it seems that chr(92) may never be required because another option should be to change the last line above to:
              file.remove( a5.get_path() + "\\" + fselected
              I haven't tried this last idea in a working app but I just tested this in the interactive editor and it worked just fine:
              ui_msg_box( "TEST", "filename" + "\\" + "test.dbf" )

              Training session complete. Hope it will be useful. And I learned something, too. (I've heard that teachers often learn more than their students. Maybe it's true?!)

              Cal Locklin
              www.aimsdc.net

              Comment


                #8
                RE: Import and relative file delete

                Whoa! That's really wierd! The first preview of my first post had everything in blue after the first "code" section. Then it "corrected itself" after I posted the second time.

                In this case, I've only learned that "computers sometimes do wierd things." Unfortunately, I learn that almost every day! (or is that "hour"?)

                Comment


                  #9
                  RE: Import and relative file delete

                  And, now that I think about it, it seems that chr(92) may never be required because another option should be to change the last line above to:
                  file.remove( a5.get_path() + "\\" + fselected )
                  I haven't tried this last idea in a working app but I just tested this in the interactive editor and it worked just fine


                  Yes Cal, it is perfectly fine to use "\\" in practice. I have never used chr(92) in any of my code anywhere. The Web App Server deals with file paths extensively and works well with the double-backslash.

                  Thanks for posting the lesson. I think this is something that very few people actually understand, they just use the chr(92) because they've seen someone else do so. There's nothing wrong with using it, it simply comes down to personal preference, but it's nice to know what your options are.

                  -Lenny

                  Lenny Forziati
                  Vice President, Internet Products and Technical Services
                  Alpha Software Corporation

                  Comment


                    #10
                    RE: Import and relative file delete

                    It had a little bit of help correcting itself ;)

                    Lenny Forziati
                    Vice President, Internet Products and Technical Services
                    Alpha Software Corporation

                    Comment


                      #11
                      RE: Import and relative file delete

                      I'm glad ya'll clarified that. I've been using

                      ceiling(exp(4*log(math_pi))-6))

                      in practice. Now I can shorten some expressions!
                      There can be only one.

                      Comment


                        #12
                        RE: Import and relative file delete

                        Didn't paste in properly, should have "chr(" in front. Sorry to mislead.
                        There can be only one.

                        Comment


                          #13
                          RE: Import and relative file delete

                          Looks like a good starter for an obfuscated Xbasic contest. But I know you can do better than that. How's this one?

                          Code:
                          eval(chr(val(time("h",ctodt("5/9/2005 9:37:05"))+9))+substr("Alpha Software has the best customers",16,1)+chr(val(alltrim(str(val(iif(version()=6,"108","109"))+version(),10,2,","))))+"(ceiling(exp(4*log(math_pi))-6)"+chr(asc(")")))
                          Unfortunatley, it only works for versions 5 and 6

                          Lenny Forziati
                          Vice President, Internet Products and Technical Services
                          Alpha Software Corporation

                          Comment


                            #14
                            RE: Import and relative file delete

                            ? "This is a test of coding a backslash "+eval(chr((val(right(alltrim(str(99+mynum)),2))+val(left(alltrim(str(99+mynum)),1)))+(99-mynum))+chr((val(right(alltrim(str(104+mynum)),2))+val(left(alltrim(str(99+mynum)),1)))+(99-mynum))+chr((val(right(alltrim(str(114+mynum)),2))+val(left(alltrim(str(99+mynum)),1)))+(99-mynum))+chr((val(right(alltrim(str(40+mynum)),2))+val(left(alltrim(str(99+mynum)),1)))+(99-mynum))+chr((val(right(alltrim(str(57+mynum)),2))+val(left(alltrim(str(99+mynum)),1)))+(99-mynum))+chr((val(right(alltrim(str(50+mynum)),2))+val(left(alltrim(str(99+mynum)),1)))+(99-mynum))+chr((val(right(alltrim(str(41+mynum)),2))+val(left(alltrim(str(99+mynum)),1)))+(99-mynum)))+evaluate_template("mynum = floor(val(ui_get_number(\"Please\",\"Pick an integer between 60 and 85\",\"78\")))")+ "character."
                            There can be only one.

                            Comment

                            Working...
                            X