Powershell read a file in directory and write to a SQL table

hey guys i have an issue here and dont really know where to begin. I need a powershell app to watch a directory and whenever a new file gets generated that file name gets written to a SQL database table.
can someone point me in the right direction im literally clueless on this one.
Thanks
Rich T.
Rich Thompson

Search in the gallery for "FileSystemWatcher"
¯\_(ツ)_/¯

Similar Messages

  • How to read a files in directory and its subdirectories

    I wants to read all files in directory, its subdirectory and further till end the files in the subdirectory of subdirectories.
    I have some idea the I can do this by using recursive function, using the functions isDirectory(), File.list() etc.
    How much you can please help me. (via code of logic)

    import java.io.*;
    import java.net.*;
    public class MyCon
    public static void main(String args[]) throws
    IOException
    File file=new File("c:/");
    openDirectory(file,"");
    System.in.read();
    static void openDirectory(File file,String indent)
    String[] string=file.list();
    String path=file.getAbsolutePath();
    for(int i=0;i<string.length;i++)
    File temp=new File(path+"/"+string);
    if(temp.isDirectory())
    openDirectory(temp,indent+" ");
    else
    System.out.println(indent+temp.getName());

  • How can I read a file with ASCII Special Character into a SQL table using SSIS 2008?

    I've tried everything to read this file and am getting no where.   Help how can I read this file and load a SQL table?
    RS - AscII - 30  (Record Separator)
    GS - AscII - 29 (Group Separator)
    Thank you for your assistance - Covi
    Mark Covian

    We can use script component as source/transformation to read the text file and assign the contains to a string. Split the string by chr(30)  i.e RS and finally stored into an array or write to the output buffer of the script component.
    For example on how to use script component refer this link
    http://social.technet.microsoft.com/Forums/en-US/6ff2007d-d246-4107-b77c-624781baab38/how-to-use-substring-in-derived-column-in-ssis?forum=sqlintegrationservices
    Regards, RSingh

  • Read from file, compare string and return a part

    Hello, is there a reasonable good way to read text file containing information, and if string comparison is successfull, return a nother part of the string.
    What i have done so far:
    set file_name to (path to desktop as text) & "filename.txt"
    set F to open for access tiedosto with write permission
    set file_information to (read F)
    close access F
    (i will be moving this to Application Support/Appname/ when i figure it out).
    The data in the file is in following format
    12234567890Name1
    98765432123Name2
    92347928347Name3
    What im stuck now is:
    I need to compare each line the 10 numbers with search string, if match is found, the name part should be returned.
    Any idea's?

    You already read in the text file, so you need to put the data thru a repeat loop:
    repeat with name_part in paragraphs of file_information
    -- ((character 1 thru 10 of name_part) as string) is the first 10 digits of name part
    if ((character 1 thru 10 of name_part) as string) is search_string then return name_part
    end

  • Reading all files on directory using "utl_file" package...

    I need to read all files in directory via PL/SQL. I don't know
    name files (are data dynamics create for automation system),
    only I know your extensions.
    Can I do this using the package "utl_file" or I need to create
    program in another language (C, C++, for example)?
    Any ideas...
    Thanks.

    Hi,
    you can't do that with the UTL_FILE package (it can't retrieve
    file names).
    A very simple solution would be, if you created on OS-level a
    file which contains the filenames of directory and then read this
    file using UTL_FILE. With the information on all file names you
    can enter a loop which opens and reads all files again using
    UTL_FILE.
    A more mundane solution could be to use the features on the iFS.
    Cheers
    Gerald

  • File Adapter - Reading 2 files from sender and one file to receiver

    All - I am looking for a best solution for reading two files from sender and generating one file to the receiver.
    Here is the scenario
    Sender file s - A is a master file. B is a detail file; B will have a one to many records for each record of File A.. that is the relation ship between 2 files..  I am looking for a better solution to
    Example
    Input:
    File A will have a record like "summary1 ABC 1234"
    File B will have a record like "Detailfor Summary1 CDF 8679"
    Output:
    File C shall have a record "consolidatedofSummary&Detail ABC 1234 8679"
    1) read records of master row and detail row from these 2 files
    2) do the mapping to the receiver output format which it is creating for records with some harcoded values and based on the values from master and detail rows of sender file
    if I can accomblish reading sender files and do the mapping to the receiver , assume that mapping to the receiver format would not be cumbersome.
    please help me...
    Thanks

    Hi Gopal,
    Ur approach to the interface is perfect.... Go ahead.
    For selecting multiple files in source use Advanced Selection for files.. and specify the directory paths and also the file name shema...
    This will fetch the 2 files into the integration engine... then u map the 2 source files to one target file(2:1 mapping).
    Specify accordingly the receiver side FCC and test it end to end...
    If u face any prblm post here... some1 will help u out..
    Babu

  • HOW TO READ MULTIPLE FILES FROM DIRECTORY

    i have a directory with 100 .sql insert scripts.i want to read all .sql files from directory and execute the insert script automatically.

    Let's suppose you have 3 files: "first.sql", "second.sql" and "third.sql". Create a file named "all.sql" in the same directory, containing this:
    @@first.sql
    @@second.sql
    @@third.sqlRun "all.sql".

  • How to delete a READ ONLY file from Directory

    Hi Friends,
    how to delete a READ ONLY file from Directory , file is in my system only.
    Please help me .
    note: its read only file.
    Thank you.
    Karthik.

    hI,
    try with this statement.
    delete dataset <datasetname>.
    this will definitely work.
    Regards,
    Nagaraj

  • Create directory and write files to it

    i have installed tomcat 3.2.3 and am using ms access as databse.
    through my jsp code i need to create random directories on the server and write files to it(need to have write access on the directories).
    how do i do it?? thanx in advance.

    You can include java.io in ur jsp page only using
    <%@ page language="java" import="java.io.File %>
    then u can create directories on the fly on the server using
    mkdir(s) method of the FILE Object.
    You will have to specify the path while creating a File object.
    You will get the application's path using
    application.getRealPath() method .... to wich u can append
    whatever u will like...
    Once u got the directory u can also create files using file object
    Hope this is of any help...
    Feel free toa sk if i could not satisfy u...

  • Powershell read CSV file line by line and only first header

    I have a CSV file, which reads like this:
    read, book
    read1, book1
    read2, book2
    I want to read only the first value, before comma one line at time,
    meaning first time it will be
    read
    read1
    read2
    no headers and i want to pass that value to a variable for a if condition.
    I have script it read line by line but it reads both values before coma and after line by line, so instead of having three values i'm ending with 6 values.
    $file = Import-CSV c:\script\server.csv
    $file | ForEach-Object {
            foreach ($property in $_.PSObject.Properties) 
    $property.Name
    $property.Value
    #replace = $property.Value

    If you can work with headers then do so as it will make your life easier.
    with a csv file called server.csv like this:
    headername1, headername2
    read, book
    read1, book1,
    read2, book2
    and this bit of code 
    $file = Import-CSV c:\script\server.csv
    #output to host, file or directly pipe the command above.
    foreach($cell in $file.headername1){ if($cell -eq $something){ }}
    will evaluate the content of each cell to $something.
    This is because Powershell will grab the first row and claim that as a header name.
    So whatever you put in cell A1 in excell will end up as name of the first collumn and its corresponding property (e.g. $file.A1 oor $file.headername1 if you will).

  • Read from one file ... and write

    I had written below code to read from a file
    which has input in below format...
    $ filla
    % dillla
    I wrote a code to read from the below file and I want to write into another file...
    in another format...like
    filla, $
    dilla, %
    I wrote as below... but my code doesn't work....i commented most of the code becoz I doubt ....
    I read the file...line by line...
    each line has two words one is special characters($ or %) and the other is some name... separated by space..
    I stored both in different arrays...and thought to write them in output file...
    import java.io.*;
    public class data
           public static void main(String args[])
                int kMaxLines = 60000;            
                  String[][] valuePairs = new String[2][kMaxLines];
                  String symbol [] = new String[kMaxLines];
               String name [] = new String[kMaxLines];
               int k = 0;
                       try            
                      FileInputStream fstream = new FileInputStream("c:/inputs.txt");
                      DataInputStream datastream = new DataInputStream(fstream);
                      BufferedReader br = new BufferedReader(new InputStreamReader(datastream));
                      //FileWriter output = new FileWriter("c:/output.txt");
                 //BufferedWriter bw = new BufferedWriter(output);
                      String names; 
                      String strLine;
                      int line = 0;
                      while ((strLine = br.readLine()) != null)
                           String temp_strs[] = strLine.split(" ");
                          for (int j = 0; j < 2; j++)
                          valuePairs[j][line] = temp_strs[j];
                         //System.out.println(temp_strs[0] + " " + temp_strs[1]);
                          symbol[k]= temp_strs[0];  
                          name[k]=temp_strs[1];
                          line++;
                          k++;
                      for (k=0; k < kMaxLines; k ++)
                      System.out.println(symbol[k]+ "" + name[k]); // when I print it is giving null value...
                      } // so what I do to get those values into global array...
                          datastream.close();
                // to write to file
                   //String names_str;
                        //bw.write("@relation train");
                  //for(k=0; k<kMaxLines; k++)
                    //  names_str = names+""+name[k];
                   //bw.write("@attribute names" + " {"+names_str+"}");
                   //bw.write("@attribute class {+,-}");
                   //bw.write("@data"+"\n");
                    // for (k=0;k<kMaxLines; k++)
                   //bw.write("name[k]+","+symbol[k]");
                       catch (Exception e)
                      //file not found exception...
                            e.printStackTrace();
     

    Why the multiple arrays?
    I'd just read it into List<String[]>... an extensible collection of "the fields on each line"... then you just write them out as required.
        second-field + comma + first-field.
    I suggest your next move should be to take a backup copy of your current class then rip-all that commented-out code out of it, and reformat it properly... starting from a clean(er) slate... then try swapping over to a List<String[]> instead of that cumbersome String[][] matrix.
    Try that... if you get stuckeroonied then don't be afraid to ask again.
    Cheers. Keith.

  • Read all files in chield and their chield's directory

    I am trying to make a program which read all files in a directory and its subdirectory like scandisk program of window's operating system. I gause this I can do via recursion using the methods isDirectory(), File.list() etc. Please help me to implement this problem in code.
    Regards
    yogesh

    you guys should collaborate,
    http://forum.java.sun.com/thread.jsp?forum=4&thread=153110&start=0&range=30#443719

  • Reading Data from Unix file and write into an Internal table

    Dear all,
                     I am having an requirement of reading data from unix file and write the same into an internal table..how to do that ...experts please help me in this regard.

    Hi,
    do like this
    PARAMETERS: p_unix LIKE rlgrap-filename OBLIGATORY.
    DATA: v_buffer(2047) TYPE c.
    DATA: BEGIN OF i_buffer OCCURS 0,
            line(2047) TYPE c,
    END OF i_buffer.
    * Open the unix file..
    OPEN DATASET p_unix FOR INPUT IN TEXT MODE.
    <b>IF sy-subrc NE 0.
    *** Error Message "Unable to open file.
    ELSE.</b>
       DO.
         CLEAR: v_buffer.
         READ DATASET p_unix INTO v_buffer.
         IF sy-subrc NE 0.
            EXIT.
         ENDIF.
         MOVE v_buffer TO i_buffer.
         APPEND i_buffer.
      ENDDO.
    ENDIF.
    CLOSE DATASET p_unix.
    <b>Reward points if it helps,</b>
    Satish

  • Read form file ok, try to write to same file : FileNotFound

    My application starts reads an xml file. When I try to write back to the XML file I get
    javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:\C:\Documents%20and%20Settings\alzoid\My%20Documents\Netbeans%20Projects\Laptop\UserSettings.xml (The filename, directory name, or volume label syntax is incorrect)
    I did SOP for file.getAbsolutePath() before it read and writes and the ouput is the same:
    "C:\Documents and Settings\alzoid\My Documents\Netbeans Projects\Laptop\UserSettings.xml"
    Here is the code that reads (works):
    public void fillToFile() {
            xmlFile = new File(TO_FILE_NAME);
            try {
                if(xmlFile.exists()) {
                    setToPocketPC(db.parse(xmlFile));
                } else {
                    createToPocketPC();
            } catch (SAXException se) {
                       se.printStackTrace();  
            } catch (IOException ioe) {
                ioe.printStackTrace();
        }Here is the code that throws the exception:
    private void writeDocumentToFile(Document doc,String fileName){
           try {
            xmlFile = new File(fileName);  
            System.out.println(xmlFile.getAbsolutePath());
            source = new DOMSource(doc);
            result = new StreamResult(xmlFile);
            transformer.transform(source, result); //fails here
            xmlFile = null;
            source = null;
            result = null;
           } catch (TransformerConfigurationException tce) {
               tce.printStackTrace();
           } catch (TransformerException te) {
               te.printStackTrace();
           } /*catch (IOException ioe) {
               ioe.printStackTrace();
        }The strange thing is I tested the read/write last week and it worked. I did not change any code. If I copy the file:\c:\Documents%20and%20Settings.... Path into windows explorer it finds the file.
    Any suggestions?
    Thanks
    Al

    I'm not sure why either, though the API docs mention "takes File to populate a StreamResult", which really does not make any sense. The File would be populated by the StreamResult. The way it is written would only make sense, at least to me, if the File was being used as input.
    Glad I could help. Best of luck.
    - Saish

  • Count files in Directory and the number of files in each sub directory

    Hello,
    I trying write a method which will start at a root of a file and count all the files in that directory. Then count all the files in each sub directory.
    import java.io.File;
    import java.io.FilenameFilter;
    import java.io.IOException;
    public class RunScan {
         * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              File file = new File("/home/robert/count");
              File[] files = file.listFiles();
              traverse(files);
              printfiles();
         private static int totalNumFiles = 0;
         private static int totalNumDir = 0;
         private static int filePerDir = 0;
         private static int subDir = 0;
         private static void traverse(File[] files) {
    for(int i = 0; i < files.length; i++) {
    if(files.isDirectory()) {
         totalNumDir++;
         printDir(files[i].toString());
         traverse(files[i].listFiles());
    totalNumFiles++;
    filePerDir++;
         private static void printfiles(){
              System.out.println("total files "+ (totalNumFiles));
         System.out.println("totls sub dir "+ totalNumDir);
         private static void printDir(String dirName){
              System.out.println("Total Files in "+dirName+" "+filePerDir);
              filePerDir = 0;

    Hint: Google "visitor pattern." This gives clues how to build a re-usable solution that can you use for future traversals that do things other than just file counts. Here's a teaser of an simple interface:
    public interface TreeVisitor {
    * Processes a single file or directory. <em>Tip:</em> If you want to track the number of
    * items processed, this function is the best place to update a counter.
    * Implementors of this method should not throw checked exceptions.
    * @param item The file or directory process.
    * @param depth Number of levels below top of traversal tree (0 = top of tree).
    public void visit(File item, int depth);
    }

Maybe you are looking for

  • Latest Imovie 10.0.7  doesnt allow sharing of movies

    The latest release of Imovie 10.0.7  (march 2015) doesnt allow me to share the movie Trying to click any of the icons within this share dialogue does nothing , no error message , no spinning wheel , nothing. It actually looks like half the product is

  • CM 7.0(2) licensing question

    Hello, I upgrade our CM servers to version 7.0(2) about 6 weeks ago. I had Cisco issue me 2 temp Node licenses. I have received my permanent license and uploaded it. How do I verify that CM is actually using the permanent license that I uploaded and

  • Pdf form modification

    Hi all, I have to modify the form HAP_PDF_OFFLINE_FORM according to the note 1372480. I am unable to get the exact modification where i have to do..? Note says: Double-click the element "BODY -> T_ELEMENTS -> DATA". In the scripting for the field, de

  • Album Covers aren't matching up

    The album covers don't match with the correct albums on the iPad. They are correct on the computer in my iTunes account but not on the actual iPad itself. Any ideas on what to do??

  • Find elements serial number costco

    cannot locate correct serial number for a costco purchased copy of elements 12.  Have a reflective adobe sticker but no variation unlocks.  Installing under win7.  is there a support 800 number?