Wednesday, March 7, 2012

Can SQL search for a .txt document

Good Morning,
I am very new to SQL and I'm haveing a hard time codeing some
automation.
I'd like to look for c:\ftp\prod.txt every 5 minutes and when found,
delete it and run a
DT package that will import other .txt documents.
Thanks
RobertHi Robert,
I wrote something similar up in my blog
(http://sqlblogcasts.com/blogs/tonyr.../05/19/450.aspx).
You can add a linked server into Indexing Service (which must be running to
do this).
EXEC sp_AddLinkedserver 'IDXServer', 'Indexing Service', 'MSIDXS', 'System'
You can now access the File System by doing simple queries, your query would
be something like this...
SELECT *
FROM OPENQUERY( IDXServer,
'SELECT Directory,
FileName,
Size
FROM SCOPE('' "c:\" '')
WHERE FileName LIKE 'prod.txt''
AND Directory = ''c:\ftp'' ')
Tony.
Tony Rogerson
SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL
Server Consultant
http://sqlserverfaq.com - free video tutorials
"Robert" <rghutchinson@.geisinger.edu> wrote in message
news:1148997621.064423.148160@.u72g2000cwu.googlegroups.com...
> Good Morning,
> I am very new to SQL and I'm haveing a hard time codeing some
> automation.
> I'd like to look for c:\ftp\prod.txt every 5 minutes and when found,
> delete it and run a
> DT package that will import other .txt documents.
> Thanks
> Robert
>|||Also take a look at these 2 undocumented (so be careful) procedures
master..xp_getfiledetails 'c:\ftp\prod.txt '
master..xp_fileexist 'c:\ftp\prod.txt '
And besides that you can also use DTS with the FSO (File System Object)
Denis the SQL Menace
http://sqlservercode.blogspot.com/|||Thanks so much Tony, I'll try this.

No comments:

Post a Comment