Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Scan Directory

Author  Topic 

joblenis
Starting Member

29 Posts

Posted - 2007-11-01 : 11:18:05
Hey guys,

I have a procedure that runs everyday which takes the IIS log file from the previous day and imports it and calcs values. I would like to change this from taking the previous day to scanning all the file names in the folder and comparing them to a database to see if they have already been scanned before. I already have a table called DatesScanned which lists the filename and scandate.

IE:

D:\Logs\file1.log
D:\Logs\file2.log
D:\Logs\file3.log
D:\Logs\file4.log

The 4 file names will be scanned and compared to DatesScanned to see which has been imported already.

Can anyone point me to a resource or information on how I would get the directory listing of a folder so I could compare it to the DatesScanned table.

Thanks a bunch!

Jeff

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-01 : 11:42:57
you can use xp_cmdshell to run command line and return the results to a table

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

joblenis
Starting Member

29 Posts

Posted - 2007-11-01 : 12:20:44
Thanks! Ok I got that to run, now I need to filter it so it only shows the filename. Then I will need to query it against the other table and export the filenames that have not been imported to a file.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-01 : 13:01:30
Here, read this

This gives you more control over directory access

http://weblogs.sqlteam.com/brettk/archive/2005/06/28/6895.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

joblenis
Starting Member

29 Posts

Posted - 2007-11-01 : 15:10:44
Thanks for the article :)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-01 : 15:12:49
Did you see how the article shows you how to store the directory into a table?

You then just have query the table and do the work you want

The re-run the EXEC DIR command to refresh the table



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -