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 Csv files in a subdirectory

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

    Import Csv files in a subdirectory

    What will be the best way to create an operation to import all files in a folder to a table?
    I have submitted a sample app Multiupload.
    I have a procedure that imports a single file from the menu form.
    I would like to import all Csv files in the subdirectory to a table called products.

    #2
    Re: Import Csv files in a subdirectory

    I haven't looked at your upload other than to open the zip. You seem to have multiple .csv files in a subdirectory of the main database. I will assume that the .csv files all have the same structure.

    An import to an existing table is generally handled with an import operation which really imports to a temporary table and then appends to the existing table. If you look at the xbasic behind such an import, you will see that you can import from different tables by merely changing the name of the source file. You can derive the possible source file names with a filefind.get(). Wrap the import in a loop which feeds the source file names to the import and you're done.

    Discussed here.
    There can be only one.

    Comment


      #3
      Re: Import Csv files in a subdirectory

      Thanks for the response.
      Yes, all the csv files will have the same format and data order.
      I can import one at a time, But I would like to import all the files in the subdirectory.
      I did not find a thread about nor in the Help DB.
      The only reference I found was import.
      There must be a command to read the file names and proceed to import

      Comment


        #4
        Re: Import Csv files in a subdirectory

        There must be a command to read the file names
        filefind.get()


        and proceed to import
        no, you have to script the import and feed the names to the script. (Change the import operation to a script. Right click on the operation name, choose view xbasic. Save that, modify it.)

        But I would like to import all the files in the subdirectory.
        Check the link I provided earlier.
        There can be only one.

        Comment


          #5
          Re: Import Csv files in a subdirectory

          Attached is your database with a new button on your form. I originally used the xbasic from your import but it wouldn't work for some reason, so I re-did the import and used the xbasic from that.

          This prompts you for a folder, then parses the csv files found in that folder.

          Comment


            #6
            Re: Import Csv files in a subdirectory

            Stan and David Thanks for the response I will get work on it.
            I will be away for a couple of days.

            Comment


              #7
              Re: Import Csv files in a subdirectory

              I am back and I am having the this error after i did modiy the latest zip app.

              File import not found. 'C:\AlphaForum\multiupload2\datatxt\'.
              What Did I do wrong?


              Here is the code:

              'Date Created: 23-May-2009 10:46:44 PM
              'Last Updated: 29-May-2009 12:57:20 PM
              'Created By : davidk
              'Updated By : Frank
              dim path as C
              dim FILEFIND as C

              'path = "C:\\"
              path = "C:\AlphaForum\multiupload2\datatxt\\"'path = UI_GET_PATH ("Enter Path","", "c:\\")
              'FILEFIND = filefind.get(path + "*.TXt", FILE_FIND_NOT_DIRECTORY, "PN")
              FILEFIND = (path + "*.TXT", FILE_FIND_NOT_DIRECTORY, "PN")
              if (FILEFIND = "") then
              'The directory is empty
              ui_msg_box("Import Product", "No txt files in this folder")
              Else

              for each txttable in FILEFIND


              import_filename = filename_decode(txttable)

              temporary_import_table = file.temp_path_get()+ "products_temp_table.dbf"
              import_destination_table = "products"

              import_filename = filename_decode(txttable)
              if file.exists(import_filename) = .f. then
              ui_msg_box("Error","File to import not found: '"+import_filename+"'.",ui_stop_symbol)
              end
              end if


              ON ERROR GOTO ERROR23052009232037819


              import.type = 0
              import.names = "none"
              import.file = import_filename
              import.db = temporary_import_table
              import.skip_lines = 0
              import.skip_bytes = 0
              import.field_sep = ","
              import.record_sep = "<CR><LF>"
              import.text_qualifier = ""
              import.record_len = 27
              import.rem_blanks = .F.
              import.escape_newlines = .F.
              import.import_encoding = "default"
              import.fields = 3
              import.field1 = "locale,c,0,20,0"
              import.field2 = "prod,c,1,20,0"
              import.field3 = "prodmonth,c,2,15,0"
              import()

              'Prompt for confirmation before appending the records that were imported into the temporary table.......
              dim rec_count as n
              rec_count = a5_get_records_in_query(temporary_import_table, ".t.")
              message_text = "" + rec_count + " record(s) will be imported into '"+import_destination_table+"'."+crlf(2)+ "OK to proceed?"
              operation_result=ui_msg_box("Import Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
              If operation_result <> ui_ok_selected then
              end
              end if

              a_tbl = table.open(import_destination_table)
              append.t_db = temporary_import_table
              append.m_key = ""
              append.t_key = ""
              append.m_filter = ""
              append.t_filter = ""
              append.type = "All"
              append.m_count = 3
              append.m_field1 = "LOCALE"
              append.m_exp1 = "@products_temp_table->LOCALE"
              append.m_field2 = "PROD"
              append.m_exp2 = "@products_temp_table->PROD"
              append.m_field3 = "PRODMONTH"
              append.m_exp3 = "@products_temp_table->PRODMONTH"
              append.t_count = 0
              a_tbl.append()


              GOTO CONTINUE23052009232037819
              ERROR23052009232037819:
              ON ERROR GOTO 0
              ui_msg_box("Error","Error running Import Operation"+crlf()+error_text_get())
              END
              CONTINUE23052009232037819:

              a_tbl.close()
              a5_imp_append_op_result(a_records_processed,a_records_total,a_records_violated,import_destination_table)

              'In case the destination table is not already in the Database, add it...
              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


              next

              end if

              Comment


                #8
                Re: Import Csv files in a subdirectory

                Code:
                FILEFIND = [B]filefind.get[/B](path + "*.TXT", FILE_FIND_NOT_DIRECTORY, "PN")
                not

                FILEFIND = (path + "*.TXT", FILE_FIND_NOT_DIRECTORY, "PN")
                There can be only one.

                Comment


                  #9
                  Re: Import Csv files in a subdirectory

                  Thanks, I changed the line ' remarks and it works.
                  I am attaching a new revised app with all the options in the main form, fully working. Someone can benefit from it.
                  I am keeping many of the ' remarks line as notes.

                  Yet one more need, How do I make the last button in the main form or the following code run silently?
                  I can make it to stop asking for OK to import, but I can not stop it from reporting the import.


                  'Date Created: 23-May-2009 10:46:44 PM
                  'Last Updated: 30-May-2009 01:19:47 PM
                  'Created By : davidk
                  'Updated By : Administrator
                  dim path as C
                  dim FILEFIND as C

                  'path = "C:\\"
                  path = "C:\multiupload2\datatxt\\"
                  'path = UI_GET_PATH ("Enter Path","", "c:\\")
                  FILEFIND = filefind.get(path + "*.TXt", FILE_FIND_NOT_DIRECTORY, "PN")
                  'FILEFIND = (path + "*.TXT", FILE_FIND_NOT_DIRECTORY, "PN")
                  if (FILEFIND = "") then
                  'The directory is empty
                  ui_msg_box("Import Product", "No txt files in this folder")
                  Else

                  for each txttable in FILEFIND


                  import_filename = filename_decode(txttable)

                  temporary_import_table = file.temp_path_get()+ "products_temp_table.dbf"
                  import_destination_table = "products"

                  import_filename = filename_decode(txttable)
                  if file.exists(import_filename) = .f. then
                  ui_msg_box("Error","File to import not found: '"+import_filename+"'.",ui_stop_symbol)
                  end
                  end if


                  ON ERROR GOTO ERROR23052009232037819


                  import.type = 0
                  import.names = "none"
                  import.file = import_filename
                  import.db = temporary_import_table
                  import.skip_lines = 0
                  import.skip_bytes = 0
                  import.field_sep = ","
                  import.record_sep = "<CR><LF>"
                  import.text_qualifier = ""
                  import.record_len = 27
                  import.rem_blanks = .F.
                  import.escape_newlines = .F.
                  import.import_encoding = "default"
                  import.fields = 3
                  import.field1 = "locale,c,0,20,0"
                  import.field2 = "prod,c,1,20,0"
                  import.field3 = "prodmonth,c,2,15,0"
                  ' The next 2 lines do not work only the 3rd line works
                  ' --- how to change to silent?
                  ' import.run_silent()
                  ' import.run(.t.,.f.)
                  import()

                  'Prompt for confirmation before appending the records that were imported into the temporary table.......

                  dim rec_count as n
                  rec_count = a5_get_records_in_query(temporary_import_table, ".t.")
                  message_text = "" + rec_count + " record(s) will be imported into '"+import_destination_table+"'."+crlf(2)+ "OK to proceed?"
                  operation_result=ui_msg_box("Import Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
                  If operation_result <> ui_ok_selected then
                  end
                  end if

                  a_tbl = table.open(import_destination_table)
                  append.t_db = temporary_import_table
                  append.m_key = ""
                  append.t_key = ""
                  append.m_filter = ""
                  append.t_filter = ""
                  append.type = "All"
                  append.m_count = 3
                  append.m_field1 = "LOCALE"
                  append.m_exp1 = "@products_temp_table->LOCALE"
                  append.m_field2 = "PROD"
                  append.m_exp2 = "@products_temp_table->PROD"
                  append.m_field3 = "PRODMONTH"
                  append.m_exp3 = "@products_temp_table->PRODMONTH"
                  append.t_count = 0
                  a_tbl.append()


                  GOTO CONTINUE23052009232037819
                  ERROR23052009232037819:
                  ON ERROR GOTO 0
                  ui_msg_box("Error","Error running Import Operation"+crlf()+error_text_get())
                  END
                  CONTINUE23052009232037819:

                  a_tbl.close()
                  a5_imp_append_op_result(a_records_processed,a_records_total,a_records_violated,import_destination_table)

                  'In case the destination table is not already in the Database, add it...
                  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


                  next

                  end if

                  Comment


                    #10
                    Re: Import Csv files in a subdirectory

                    Try removing the line:

                    a5_imp_append_op_result()

                    I think that will do it.

                    Raymond Lyons

                    Comment


                      #11
                      Re: Import Csv files in a subdirectory

                      Thanks, I did miss that line.
                      I new about part 1, this line ask for input to prevent silent mode.

                      rec_count = a5_get_records_in_query(temporary_import_table, ".t.")
                      message_text = "" + rec_count + " record(s) will be imported into '"+import_destination_table+"'."+crlf(2)+ "OK to proceed?"
                      operation_result=ui_msg_box("Import Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
                      If operation_result <> ui_ok_selected then
                      end
                      end if

                      Actually, in some cases this is good.

                      Comment

                      Working...
                      X