Question

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,

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top