Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004

    Unanswered: Read a file name from network folder automatically for a BULK INSERT

    Hi again all,

    Is there a way to read a file name automatically from a network folder? I can successfully bulk insert from this particular folder. The next step is as I add files, I wish to bulk insert the latest file added so the program must make that determination and import that specific file. I can delete the older files if necessary and save them elsewhere but it would still be nice to be able to read the file name. I then wish to store the name of this file, whatever it is, into a field called "SourceFileName" in my table that I am bulk inserting into. Does anyone have an example in dynamic SQL? Thanks.


  2. #2
    Join Date
    Nov 2004
    on the wrong server
    Provided Answers: 6
    DECLARE @FilePathToSQLFiles VARCHAR(2000)
    DECLARE @Path VARCHAR(2000)
    SET @FilePathToSQLFiles = 'C:\' 
    CREATE TABLE #SQLFiles ( SQLFileName VARCHAR(2000))
    SET @Path = 'dir /b "' + @FilePathToSQLFiles + '*.sql"'
    EXECUTE master.dbo.xp_cmdshell @Path
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts