Using T-SQL to Query a File System Folder

前端 未结 2 1092
礼貌的吻别
礼貌的吻别 2021-01-12 11:14

Is it possible to query a folder in TSQL, from SQL Management Studio, and return a list of file names? If so, how?

相关标签:
2条回答
  • 2021-01-12 11:17

    You can use xp_cmdshell.

    Example:

    EXECUTE master.dbo.xp_cmdshell 'DIR "C:\YourDirectory\" /A-D /B'
    

    There's a good, full example with more options here.

    0 讨论(0)
  • 2021-01-12 11:25

    CLR integration is also an option, if you're not comfortable with allowing xp_cmdshell to be executed.

    See MSDN.

    0 讨论(0)
提交回复
热议问题