开发者

Checking a directory contains files or not - tsql

开发者 https://www.devze.com 2023-01-23 11:02 出处:网络
I\'m trying to code a mssql job that does something using the files in a specific directory. But I don\'t know the name of the file / files, they will vary in time.

I'm trying to code a mssql job that does something using the files in a specific directory. But I don't know the name of the file / files, they will vary in time.

I've found xp_cmdshell command, but I can not use it because of security reasons

Is there any other way to check directory if it contains txt files or开发者_高级运维 not (and if yes get the names of them) in tsql.

Thanks in advance,


Without access to the xp_ stored procedures, no. The other way would be to create a COM object using sp_OACreate that creates a COM Scripting.FileSystemObject, but again access to this may well be restricted as it's a security issue.

As your describing this as an MSSQL job, I'm assuming this is going to be a scheduled task of some description? If so, your best option is probably going to be creating a standard Windows batch file (.BAT) that's scheduled in SQL Server agent that does the existential checking and passes whatever files are found in to your SQL script via sqlcmd/osql.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号