Looping through files in a folder, How to

Looking for plsql code to read through files in a folder, and pass the name of the file found to a parm.
The parm will then be used to open the table, process data to end of file, and then close the file. The file is then moved to an archive, and the next file in the folder is read, name of file passed to parm, file is opened, data is processed, and file is moved to archive....repeat until no files in folder.
I only need some help with reading through the folder to find the table. I have code on how to open, process and move a folder...it's the file in folder read loop I am trying to develop.
In summary, I am looking for some code showing how to read all tables in a folder and pass the name of the table found, until all files read.

emss wrote:
Yes, you understand....thank you. That's the primary objective of this thread....determine the name of the .csv file.
The putline and so forth process the file. I need to find the file, it's name, and then process the .csv file.PL/SQL itself has no mechanism built in for determining the list of files in a directory.
The Java solution is one of the easiest to implement as PL/SQL can interface fairly simply with Java functions which you can create on the database.
There are other ways, but no way is going to be completely simple.
Remember, from PL/SQL you will only really be able to get to files that the database server itself can see, so either files on the database server itself, or files on machines that the server itself has network mappings to that it can treat as if they are local files. It certainly won't be able to hack across the network to any client machines hard drive to read a list of files.

Similar Messages

  • Is it possible to loop through files in a folder, but only load those with a specific filename?

    Hello all. I have a folder with about 100 text files total, but it's really only about 25 different reports, each with multiple quarters. So, for example, it looks like this...
    Report A 2014-12-31
    Report A 2014-09-30
    Report A 2014-06-30
    Report A 2014-03-31
    Report B 2014-12-31
    Report B 2014-09-30
    Report B 2014-06-30
    Report B 2014-03-31
    Report C 2014-12-31
    Report C 2014-09-30
    Report C 2014-06-30
    Report C 2014-03-31
    ...and so on
    I need to load only report B to a table in SQL Sever 2008 R2, but I need to load all quarters for report B. I'm trying to accomplish this using a foreach loop container, but I haven't figured
    out hot to tell it to only look at report B and ignore the others. In testing, the loop always starts with report A.
    In the process, I also need to capture the date section of the filename in a variable so I can create a derived column with the date to insert into the table.
    Any ideas how to accomplish this? I'm trying to avoid putting each report in its own folder because it adds a manual step, but if there's a way to do that using a file system task before running the loop, I'm open to it.
    Thanks for any advice you have!
    WeeLass

    Have you tried specified Report B*.txt for Files : under the Collections tab ?
    Narsimha

  • SSIS - Loop through files from a file path based on the value in the variable

    Experts,
    I have a requirement where I'll be loading multiple files in to a SQL server table and archive the files when loaded. However, the challenge is , the file path should be dynamic based on the value of a variable (say, @ProductName).
    For example: If I am running the package for variable @ProductName="Product", the file path would be "\\....\Src\Product", in that case the ForEachLoop will loop through all the files in that folder, load them to the table and Archive
    the files to the "\\....\Src\Product\Archive" folder.
    Similarly, if the @ProductName="Product_NCP", the foreachloop container should loop through files in the "\\....\Src\Product_NCP" folder, load them to the table and archive them to the ""\\....\Src\Product_NCP\Archive"
    folder.
    Any suggestions? I should be able to run the package manually just by passing the "@Product" value, create Archive folder if it doesn't exist, load the data and archive the files.

    Yes
    1. Have a variable inside SSIS to get folder path. Set path based on your rule using an expression
    like
    (@[User::ProductName] == "Product" ? "\\....\Src\Product" : (@[User::ProductName] == "Product_NCP" ? \\....\Src\Product_NCP:..))
    similary archive
    (@[User::ProductName] == "Product" ? "\\....\Src\Product\Archive" : (@[User::ProductName] == "Product_NCP" ? "\\....\Src\Product_NCP\Archive" :..))
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Open Folder using Coldfusion and loop the files in the folder to the files names

    Hello,
    I have a folder with lot of .xls files in it.
    I want to access a folder using some coldfusion code and then
    "loop" through each .xls file in the folder, and while looping is
    it possible to obtain the name of each .xls file?
    Anyone who knows anything about this, your help would be
    highly aprreciated.
    Thx

    Yup, I know all about it.
    You can to if you read up on the <cfdirectory ...> tag
    in the
    documentation. A very hand tag for reading a directory, even
    includes
    the ability to filter to a certain file types. And produces a
    record
    set of the files with names, types and more.

  • Loop through files locating specific data sets

    Hi there,
    I have been given the wonderful task of developing a setup which needs to do the following using JCAPS:
    - open and read through various flat files in a folder. These flat files have random data sets in them, where a line starting with 01, marks the start of a data set and 99, marks the end of a data set. 03, marks the line where the account number can be found.
    - retrieve the account number from the data sets and verify that against an external Oracle database table.
    - if account number is found, then read the data set from the flat file and write the data set to an output file.
    - if the account number is not found in the Oracle database table, just discard the dataset and continue with the next data set.
    If you have any ideas on how to set this up, that would be much appreciated. No need to spell things out, but if anyone has worked on a scenario like this or similar using JCAPS to do the trick please let me know.
    A scenario variant is that, instead of looking up the account number against the oracle database, we can use an if-statement like "if the currency is GBP, EUR, SEK, then take the data set from the input file and write the data set to the output file.
    I can create an input OTD to read in the data sets, and an output OTD which creates the output file. There is a blank line between data sets. The structure of a data set looks like this:
    01,CITIDIRECT,2978169,080922,0401,04010900,999,,2/
    02,2978169,400515,1,080919,0000,USD,2/
    03,57787314,USD,010,2191397371,,,015,2191397371,,,030,2191397371,,,040,2191397371,,,045,2191397371,,,060,2191397371,,,072,000,,,074,000,,,100,000,0,,400,000,0,,470,000,0,/
    49,13148384226,2/
    03,57787322,USD,010,1494730626,,,015,1494730626,,,030,1494730626,,,040,1494730626,,,045,1494730626,,,060,1494730626,,,072,000,,,074,000,,,100,000,0,,400,000,0,,470,000,0,/
    49,8968383756,2/
    03,57787349,USD,010,423382915,,,015,423382915,,,030,423382915,,,040,423382915,,,045,423382915,,,060,423382915,,,072,000,,,074,000,,,100,000,0,,400,000,0,,470,000,0,/
    49,2540297490,2/
    98,24657065472,3,8/
    99,24657065472,1,10/
    Thanks & Kind Regards,
    Richard

    Yes
    1. Have a variable inside SSIS to get folder path. Set path based on your rule using an expression
    like
    (@[User::ProductName] == "Product" ? "\\....\Src\Product" : (@[User::ProductName] == "Product_NCP" ? \\....\Src\Product_NCP:..))
    similary archive
    (@[User::ProductName] == "Product" ? "\\....\Src\Product\Archive" : (@[User::ProductName] == "Product_NCP" ? "\\....\Src\Product_NCP\Archive" :..))
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Looping through files with Regular expressions ?

    Hi,
    My Question is:
    if i have the following Regular Expression,
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    The file in which i am looking for the string has multiple entries, is it
    possible to do another regular expression on the captured group (.*;)
    which is in the original Regular expression ?
    The text that is captured by the RE is of the type "(1,(2,((3,5),4)));" for
    each entry, and different entries in the file have slightly different syntax
    is it possible to loop through the file and first of all check for the presence
    of the original RE in each entry of the file
    and then secondly, check for the presence of another RE on the captured group?
    [ e.g. to check for something like, if the captured group has a 1 followed by a 3
    followed by a 5 followed by a and so on ].
    Thanks Very much for any help, i've been struggling with this for a while!!
    Much appreciated
    The code that i have so far is as follows:
    import java.util.*;
    import java.util.regex.*;
    import java.io.*;
    import java.lang.*;
    import javax.swing.*;
    public class ExpressReg {
    public String Edit;
    public ExpressReg(String editorEx){
    Edit = editorEx; // Edit = JTextArea
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    //String regrex1 = "(.*;)";
    Pattern p = Pattern.compile(regrex);
    Matcher m = p.matcher(editorEx); // matcher can have more than one argument!
    boolean result = m.find();
    if(result){                           
    JOptionPane.showMessageDialog(null, "String Present in Editor");
    else if(!result){
    JOptionPane.showMessageDialog(null, "String Not Present In Editor");

    if i have the following Regular Expression,
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    The file in which i am looking for the string has multiple entries, is it
    possible to do another regular expression on the captured group (.*;)
    which is in the original Regular expression ?Yes, the capturing group is $1 (the only one) referenced in source code as m.group(1).
    m.group() will return entire matching.
    simply use this way:
    String result = m.group(1);
    // your stuff: could be another validation
    The text that is captured by the RE is of the type "(1,(2,((3,5),4)));" for
    each entry, and different entries in the file have slightly different syntax
    is it possible to loop through the file and first of all check for the presence
    of the original RE in each entry of the file
    and then secondly, check for the presence of another RE on the captured group?Again "Yes", no limits!
    Don't need to create another Matcher, just use m.reset(anotherSourceString)..loop using the same pattern.
    Note: Take care with ".*" because regex nature is "greedy", be more specific, eg.: "\\d" just matches digits (0-9).
    Can you give us some sample of "slight difference" ?

  • URGENT:  Loop through files

    I have a package that will be run from an Oracle Job and I want to process files in a directory and load each of the files into the database. I can load one specifically, but I want to loop through all the files in the directory and load each one at a time. Any help would be greatly appreciated.
    Lisa

    I followed the instructions but when I try to create the java, I get the following error (removed the numbers in front of each line):
    and compile java source named "DirList"
    ERROR at line 2:
    ORA-29536: badly formed source: Encountered "<EOF>" at line 1, column 17.
    Was expecting:
    unknown command beginning "import jav..." - rest of line ignored.
    unknown command beginning "public cla..." - rest of line ignored.
    unknown command "{" - rest of line ignored.
    unknown command beginning "public sta..." - rest of line ignored.
    For a list of known commands enter HELP
    and to leave enter EXIT.
    unknown command beginning "throws SQL..." - rest of line ignored.
    unknown command "{" - rest of line ignored.
    unknown command beginning "File path ..." - rest of line ignored.
    unknown command beginning "String[] l..." - rest of line ignored.
    For a list of known commands enter HELP
    and to leave enter EXIT.
    unknown command beginning "String ele..." - rest of line ignored.
    unknown command beginning "for(int i ..." - rest of line ignored.
    unknown command "{" - rest of line ignored.
    unknown command beginning "element = ..." - rest of line ignored.
    For a list of known commands enter HELP
    and to leave enter EXIT.
    unknown command beginning "#sql { INS..." - rest of line ignored.
    unknown command beginning "VALUES (:e..." - rest of line ignored.
    unknown command "}" - rest of line ignored.
    unknown command "}" - rest of line ignored.
    For a list of known commands enter HELP
    and to leave enter EXIT.
    unknown command "}" - rest of line ignored.
    and compile java source named "DirList"
    ERROR at line 2:
    ORA-29536: badly formed source: Encountered "<EOF>" at line 1, column 17.
    Was expecting:
    I researched it on metalink with no luck. I'm running it on my local database (Oracle8i Release 8.1.7.0.0 - Production JServer Release 8.1.7.0.0 - Production) so this may be the problem.
    Help!
    Lisa

  • Trying to loop through files

    Sorry if this is a simple thing, I just can't seem to get it working.  Ugh.
    I'm following the example here:
    http://www.sqlis.com/sqlis/post/Looping-over-files-with-the-Foreach-Loop.aspx
    I got stuck on this section:
    The important part of this dialog is highlighted and that is "Expressions". Click on the ellipses and we will be taken through to the next screen where we can start to create the expression. In the screen that follows, from the Property column
    drop the list down and choose ConnectionString
    In the 'Property Expressions Editor' window, i can't choose Property=ConnectionString.  I just don't have it in my list.  I'm using Visual Studio Ultimate 2010.  The article is discussing SQL Server 2005 SSIS.  Maybe something changed
    b/w the two versions, or maybe I'm just not doing something right.
    This is a big problem, b/c when I try to set the OLEDB, I get this.
    Nothing is being feed into the Loop tool, and thus nothing can be mapped to the destination table in my DB.
    I thought I could just make up my own, intuitive Expression, as such.
    That doesn't do anything at all. 
    Can someone help me out?
    Thanks!!
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    So, I cancelled my other project and started over.  I’m at this section in the original link that I posted:
    The important part of this dialog is highlighted and that is "Expressions". Click on the ellipses and we will be taken through to the next screen where we can start to create the expression. In the screen that follows, from the Property column
    drop the list down and choose ConnectionString
    The whole problem here is that I don’t have the Property = ConnectionString in the Property Expression Editor window.
    This is what I have.
    There is no ConnectionString anywhere; it simply doesn't exist.
    I did set the flat file source; that's fine now.  But I have an exclamation mark in the OLEDB object (that doesn't seem right).  No matter what I do, I can't get rid of it.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • SQL Agent Permssions With SSIS for each loop not looping through files

    Hi I am Having trouble getting a ssis package to iterate through a file directory using a proxy account set up in Sql Server.
    So I have a package that loops over csv files. If I run the package manually or set the sql agent job to run as Sysadmin the pakage runs fine all files are processed.
    However if I use the proxy account. the package completes but no files are processed. there are no failures, there is no error handling set up in the control flow. the for each loop container simply does not recognise any files when run under a proxy.
    Note: the proxy is set up with credentials to access the folder. the credential is also set up with the server admin server role... still nothing
    i'm not sure is this is a ssis or permissions problem?
    Any comments will be appreciated

    Can you check this and see if you've configured all the steps correctly
    http://www.mssqltips.com/sqlservertip/2163/running-a-ssis-package-from-sql-server-agent-using-a-proxy-account/
    Also enable logging in package and see if you're getting any error messages obtained in output table/file based on the logging option you chose.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Arranging files in a Folder

    I want to be able to drag and drop files in a folder how I want them placed and not (as my Mac wants) by either Name or Type or Date Created. I just want to arrange an order and have it stay that way (not unlike a playlist).

    When I do as you describe I never get the option to "Keep arranged by" or anything pertaining to "This window only" or "All windows"
    From my Finder/Show View Options I see this:
    A box to "Always open in list view"
    A choice of Icon size and Text size
    Show columns:
    Date modified
    Date created
    Size
    Kind
    Version
    Comments
    Label
    The three more boxes asking:
    Use relative dates
    Calculate all sizes
    Show icon previews
    and at the end it asks:
    Use as defaults
    And that's all I get the chance to do.

  • How to loop through a KM Folder ?

    Hi ....can someone please let me know how  to loop through a KM Folder having many documents , files etc .
    Waiting for replies !!
    Regards
    Smita

    Hi Smita
    Here is the code:
    String rLocationtest = "/documents/Folder1";
    IResourceContext c = ResourceFactory.getInstance().getServiceContext("cmadmin_service");
    ICollection collection = (ICollection)ResourceFactory.getInstance().getResource(RID.getRID(rLocationtest),c);
    loopFolder(collection,c);
    public void loopFolder(ICollection collection, IResourceContext c){      
             try{
             IResourceList resList = collection.getChildren();
         IResourceListIterator resItr = resList.listIterator();
                 while(resItr.hasNext()){
              IResource restemp = resItr.next();
              if(restemp.isCollection() && LinkType.NONE.equals(restemp.getLinkType())){     
                             loopFolder((ICollection)restemp,c);
                                    //If the restemp is not a collection, it is a resource.
                                    //Do the resource related operations here.
         }// End of while
             }catch(Exception e){
                  e.printStackTrace();
        }//End of loopFolder
    Hope it helps
    Thanks
    Deepak

  • How to loop through CSV file

    Hi,
    I want to loop through each column of a CSV file.
    And while looping each column, I want to loop each row
    starting with the 2st row.
    I wrote the code as below, but it is looping through the rows
    starting from row 1.
    How do I make it start the loop as from row 2 in the CSV ?
    (see code below)
    Can someone tell me how to do this?
    Thx
    <!--- get and read the CSV-TXT file --->
    <cffile action="read" file="C:\Documents and
    Settings\user\Desktop\EM-CSV\test.csv" variable="csvfile">
    <!--- loop through the CSV-TXT file on line breaks and
    insert into database --->
    <table border="1">
    <cfloop index="index" list="#csvfile#"
    delimiters="#chr(10)##chr(13)#">
    <!--- <cfoutput>#listgetAt('#index#',1,
    ',')#</cfoutput><br> --->
    <tr>
    <td><cfoutput>#index#</cfoutput></td>
    <td><cfoutput>#listgetAt('#index#',2,
    ',')#</cfoutput></td>
    <td><cfoutput>#listgetAt('#index#',3,
    ',')#</cfoutput></td>
    </tr>
    </cfloop>
    </table>

    Hello, your code works perfectly.
    Now I am having a slight problem with it.
    I have added the code to check whether a particular cell of
    the CSV is blank. (see code below)
    But it is giving me error message.
    Can you please tell me what am doing wrong?
    Thx
    <!--- loop through the CSV-TXT file on line breaks and
    insert into database --->
    <cfset isRowTwoOrLater=false>
    <table border="1">
    <cfloop index="row" list="#csvfile#"
    delimiters="#chr(10)##chr(13)#">
    <cfif isRowTwoOrLater>
    <tr>
    <cfif #listgetAt(row,1, ',')# neq ''> <!--- I HAVE
    ADDED THIS PART TO CHECK WHETHER IT IS BLANK --->
    <td><cfoutput>#listgetAt(row,1,
    ',')#</cfoutput></td>
    <cfelse>
    <td><cfoutput>It is
    blank</cfoutput></td>
    </cfif>
    <td><cfoutput>#listgetAt(row,2,
    ',')#</cfoutput></td>
    <td><cfoutput>#listgetAt(row,3,
    ',')#</cfoutput></td>
    </tr>
    <cfelse>
    <cfset isRowTwoOrLater = true>
    </cfif>
    </cfloop>
    </table>

  • How to flip through multiple image files in a folder using Preview?

    On windows a default image viewing program similar to preview allows a user to press the arrow keys to flip through images within the same folder as the image file originally opened with a Preview-like application.
    How can a person filp through images in the same folder with a few keystrokes using Preview?
    thanks

    hmm...you mean there isn't a way to simply skim
    through images in a folder using an arrow or page-up
    key?? That's kind of disappointing...especially
    being forced to pre-select images...
    oceanbluesky,
    There's no reason you can't use Preview to do what you're trying to do. And there's no need to pre-select images.
    The trick is to open Preview first, and then choose Open from the File menu (or Command + O on the keyboard). When Preview's Open dialog window appears, navigate to the folder which contains your pictures. Highlight the entire folder and then press the Open button. Once the folder is open in Preview you should be able to use your arrow keys to flip through...
    Note: To avoid a storm of images from opening on your desktop, go to Preview > Preferences > Images and make sure that the "Open each image in its own window" radio button is not selected.
    Good luck!
    Andrew99
    iMac 1 GHz Flat Panel 15" PPC 768 MB RAM   Mac OS X (10.4.10)  

  • How to loop through xml records from file without ROW , /ROW tags?

    I am using dbms_XMLSave.insertXML procedure to insert xml formated record from file. MY xmlformated records does not have open and close ROW tags. I have multiple records in the file.How can I loop through without <ROW>,</ROW> tags?

    I am using dbms_XMLSave.insertXML procedure to insert xml formated record from file. MY xmlformated records does not have open and close ROW tags. I have multiple records in the file.How can I loop through without <ROW>,</ROW> tags?

  • Loop through the excel files in folder and sub folder

    hi all
    I need to loop  through all the excel fies in a folder and its sub folder which contain excel files 
    actually, my excel files contain a column  with sdate and it contain different dates in which  has to get the max  date my query is 
    "select * from  @[User::filename] where sdate=(select max(sdate) asi  from @[User::filename] )"
    loop  all the excel file in folder and its sub folder

    Take a look at the Foreach Loop.
    Here is an article about it.
    Andy Tauber
    Data Architect
    The Vancouver Clinic
    Website | LinkedIn
    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
    "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

Maybe you are looking for

  • MacBook for Graduation

    I am going to graduate high school this week, and after I receive all my gifts and stuff which is going to be cash. I am going to purchase a laptop for college. I want to get a Mac as I have been interested in them for a couple of years now, but have

  • Acrobat Pro X 10.1.5

    I had this issue prior to the update.  I open a PDF file and the program stops responding.  Un-installing and re-installing the applicatin cured it for about a day, but the problem returns.  It seems worse in 10.1.5.  Running the repair ulitity has n

  • Replication with Domain and Sub domain in Active directory sites and services

    I seen many AD enviroments and know that when you have mutiple DCs you use Active Directory Sites and services to replicate using the NTDS Settings. If you have a Domain and sub domain do you need to do this as well or does it sync up automatically b

  • EJB and large memory - need expert advise.

    Hi, I have an application that uses alot of memory. There are many clients/session connecting to this application with persistent data. Memory can be think of 2 parts: - small portion which is different from one session and another, and needs to be p

  • SSAS Cube deployment problem

    Hi! I have a problem with a cube process. I have an SQL SERVER 2014 installed with default instance. When I try to deploy my project I get an error "The name provided is not a properly formed account name". How can I fix this problem? Thanks in advan