473,883 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import Multiple Text files into a single table

6 New Member
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 14035
Mihail
759 Contributor
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
vvasude2
6 New Member
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 Contributor
This code find all files with a certain extension in one of my PC folder:
C:\Documents and Settings\Camy\M y Documents\Downl oads

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
ChrisPadgham
11 New Member
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,584 Recognized Expert Moderator MVP
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
1753
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.) in one master document. I'm not exactly sure which is the most efficient method of going about this. Should I: a. Use a container file like a CAB file and read/write separate textfiles to it? b. Save all "documents" in a collection and serialize...
5
3448
by: Buddhist[CHinA] | last post by:
The text files are not only the .txt files, but also all ascii files. Thx.
2
2727
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 the simplest way to state it. Is there a way to write to text files and save them as different names (presumably one of the variables dot "TXT") using Access VBA?
3
5722
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 //Propagation constants are elements of the vector beta for(int j=0;j<(int)(number_of_nodes);j++){ if(*(beta+j)>substrate*k && *(beta+i)<core*k){ FILE *p_j; p_j=fopen("c:\\data_j.txt","w"); }
3
7839
by: theodorej | last post by:
......how do I select multiple Excel files to import into Access? Any insights would be deeply appreciated.
19
11739
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 to get rid of this problem. I am in urgent need. plz help. Regards Anup kumar
6
30789
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 know I need to use os.path.walk() to walk through all the files, and if not os.path.isdir(filename) with open(filename,'r').read() to read all the files that are not directories. Can someone give me a clue or a very simple example that I can work...
2
4214
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(); //use millisecond and random to avoid similar filename
5
14691
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 one text file, but i need to look for a specific word, in multiple text files. all of the files are ".txt" and they are in the same folder but each of them with different names. I have written the following code: but i receive an error that i don't...
12
3188
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 wizard for each one. As part of this function, I'd like to strip the first 15 lines of data from the dataset, parse in the first 5 columns, and name the table after the information on line 3 which is the name of the street the data was taken from. ...
0
9944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9796
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10757
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10860
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9583
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6002
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3239
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.