473,378 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Import Multiple Text files into a single table

Hi all,

How can i import text files with same specefication into one table

I should be able to select multiple text files and import them automatically in the table.

The import specefication for all of them is the same.

Thanks for your support

BR,
vvasude2
Mar 6 '12 #1
5 13993
Mihail
759 512MB
Create two tables with the structure you need.
Use first table for import a text file at a time and the second one to keep all imported data

Something like this:
Expand|Select|Wrap|Line Numbers
  1. Do
  2.     Remove information from the first table (Delete query)
  3.     If the last text file has been imported Then
  4. Exit Do
  5.     End If
  6.     Import (next) text file in first table
  7.     Append first table to the second one (Append query)
  8. Loop
Mar 7 '12 #2
I have about 160 files that i need to merge and it would be not feasible to import them one at a time.

Do you happen to know the code, where i can choose an entire folder and the contents of the file gets merged based on the import spec i define
Mar 7 '12 #3
Mihail
759 512MB
This code find all files with a certain extension in one of my PC folder:
C:\Documents and Settings\Camy\My Documents\Downloads

Hope this is what you are looking for.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Sub Test() 'How to apply
  4. Dim FolderPath As String
  5.     FolderPath = "C:\Documents and Settings\Camy\My Documents\Downloads"
  6.  
  7. Dim FileExtension As String
  8.     FileExtension = ".*" 'All files in folder
  9. '    FileExtension = ".txt" 'All text files in folder
  10. '    FileExtension = ".zip" 'All zip files in folder
  11.  
  12. Dim FilePath As String
  13.     FilePath = FilesInDirectory(FolderPath, FileExtension)
  14.     Do While FilePath <> ""
  15.         FilePath = FilesInDirectory
  16.         Debug.Print FilePath
  17.     Loop
  18. End Sub
  19.  
  20. Public Function FilesInDirectory(Optional Folder As String, Optional FileExtension As String) As String
  21. Static FolderPath As String
  22. Dim FullPath As String
  23.     FullPath = Folder & "\*" & FileExtension
  24. Dim NameOfFile As String
  25.     If Folder <> "" Then 'First apply
  26.         FolderPath = Folder
  27.         NameOfFile = Dir$(FullPath)
  28.         If NameOfFile = "" Then
  29.             MsgBox ("No file mutched criteria in this folder")
  30.             FilesInDirectory = ""
  31. Exit Function
  32.         End If
  33.     Else
  34.         NameOfFile = Dir$
  35.         If NameOfFile = "" Then 'No more files
  36.             FilesInDirectory = ""
  37. Exit Function
  38.         End If
  39.     End If
  40.  
  41.     FilesInDirectory = FolderPath & "\" & NameOfFile
  42.  
  43. End Function
Mar 7 '12 #4
When you say you want to merge them, what are the rules for merging. It may be simpler to load each file into a separate table and do the merge using SQL
Mar 7 '12 #5
NeoPa
32,556 Expert Mod 16PB
vvasude2:
Do you happen to know the code, where i can choose an entire folder and the contents of the file gets merged based on the import spec i define
No. There is no such command. The pseudo-code provided in post #2 is the closest you'll get to how it can work (and the logic therein is fundamental and solid). What are you saying is wrong with that? Are you expecting this to be done for you?
Mar 7 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris Murphy via DotNetMonster.com | last post by:
Hey all, just wondering if anyone can point me in the right direction. I'm developing a solution that allows a user to store multiple text-based content (like code snippets, notes, documents etc.)...
5
by: Buddhist[CHinA] | last post by:
The text files are not only the .txt files, but also all ascii files. Thx.
2
by: ManningFan | last post by:
I'm running through a database in a loop, and each time the loop finishes I would like to export the values of some variables to new text files. In reality it's more complex than this, but this is...
3
emaghero
by: emaghero | last post by:
Hello all, I want to open multiple txt files with similar names in C++ I have attempted this with the following code //Create as many txt files as there are valid propagation constants...
3
by: theodorej | last post by:
......how do I select multiple Excel files to import into Access? Any insights would be deeply appreciated.
19
by: smugcool | last post by:
HI ALL, I am having multiple .csv files in a single directry. I wanted to import all these files in a excel file with semicolon delimeted by a single click of a button. Can anyone please help me...
6
by: borthouth | last post by:
Hi, I have just started using Python and I am slowly getting into it. I wanted to make a little script to merge all files in a directory into one. All of these files will be text files. I...
2
by: as001 | last post by:
Hi, I'm writing a windows application in C# using VS 2003. I got stuck where it has to write multiple output text files. Here's my piece of code: for loop { Random r = new Random();...
5
by: maral | last post by:
Hi every one, this is my first post here! I'm using GATE toolkit for information retrieval and text analysis, but i really need java for some parts. I have managed to find a specific word in...
12
by: Miguel Valenzue | last post by:
I collect traffic data from a machine that outputs text files with the data. I want to import each text file as it's own table into an Access database and do it without having to run the import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.