September 25th, 2012, 01:15 PM
How to list all the file names (of a folder) to a postgre table?
In a folder I have thousands of CSV file and those are named like “TUW_gp0246878” (where the “TUW_gp” part is common but the last 7 digits are different for each csv file.) and inside every csv file there are two column (year, name) and filled with data (like 10 t0 15 cases/rows). And I have a postgre table which has 3 column (id, year, name)
Now what I want is, I need a script which will automatically allow me to:
1. Fill the postgre table id field with the last 7 digit from the csv file’s name (ex: “0246878” from “TUW_gp0246878” file name) and year (from that specific csv file) to year (postgre table). As in csv there are so many rows. In that case, in every row (in the post gre table) 7 digits Id will be common.
2. As in that folder there are too many csv files, the above operation will be done for each csv file automatically and put into that postgre table.
Hope I was able to explain what I want. can anyone help?