Read matching files in a folder, read one of them and insert the Data in a Table
Posted on 2010-01-05
I really have a big Problem and no solution or idea how to solve it. I really need help from Experts like you... I am really not very goog with files and directories and I have no one to help me. So, I need a really good Program for this problem.
In a folder for example in c:\files there will be transfering 4 files with the following names
The 4 files will also have the same prefix name before the underscore and the only difference is the letters a,b,c,d after the underscore and the _c file will be a pdf file.
So, when the 4 files are in the folder the program will check if the files belong together(with the name before underscore) and when all 4 are there (a,b,c.pdf,d) then it should run. It shall also ignore all other files that not belong together. Then the Programm should take the fullpath for each one of the files. I mean the fullpath where the files will be moving.. I will move the files in the folder c:\files\old_files\current_date. The moving of the files should be the last step (I think).
So, we will take the archiving fullpath of each file and then I want to read the _d file to take some info. This file is a csv file with one line -->
invNo ; GID ; bla; blabla ;blablabla
From the _d file in need the first 2 rows invNo and GID.
So with the archiving fullpath of the 4 files and the invno and GID that we have read from the _d file, then it should be running a store procedure 4 Times with 3 parameters -->
@GID = The First row that we have read from the d file
@invNo =The second row that we have read from the d file
@Path = The archiving fullpath of all 4 files
The stored procedure than -->
INSERT INTO [Demo].[dbo].[ES00Documents]
This store procedure will run 4 times for all 4 files. At the end the files should be moved in the archiving folder.
Please, I know its really a difficult program but I need help.
Thank you for any help!!!