We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to check if a file exists for evry 10 min for an hour

Medium Priority
348 Views
Last Modified: 2012-05-11
I have to import a txt file to a table . I have to check for every 10 min for an hour if the file  exist and if the
file exists then I have to import the file . Now I am inserting all the files in a folder(C:\) to a table and checking
if a  file exists . But if the file does not exists how can check every 10 min for an hour (I dont want this through SSIS
). I want a sql for this

Thanks
Comment
Watch Question

Cedric Obinna A.Full Stack Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Can we see the code you use to check if the file exists?
HI

use

1) for checking if file exists http://www.mssqltips.com/tip.asp?tip=1272 
2)  crate a job in sql server that runs 1) every 10 min

if you use sql express , use this to define your job
http://www.sqlteam.com/article/scheduling-jobs-in-sql-server-express
Use xp_cmdshell / xp_fileexists to check the file

Make it as an SP/bat file

Schedule it to run every 10 mins.

Author

Commented:

select @loc = 'c:'
select @cmd = master.dbo.xp_cmdshell ' + char(39) + 'dir ' + @loc + '\*.*' + char(39)
SELECT @CMD2 = 'INSERT INTO a' + char(13) +
'EXEC ' + @CMD1

exec (@cmd)
and all the files that exists in the c: path will insert into temp table .Now what I want is for every 10 min for an hour I have to check if the file exists . I have to do this inside a proc . I cannot run this as a batch.
What is the problem?

Write your logic inside a procedure and schedule that procedure to run for every 10 mins.

Author

Commented:
I got this solved my self  by using while  and delay function
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>I got this solved my self  by using while  and delay function <<
Please post your solution.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2012

Commented:
To whoever is reading this in future, the script posted is useless without the DECLARE for the following local variables:
@exist_id, @exists, @CMD1, @CMD2, @file_location, @File

And the CREATE TABLE for the following temporary tables:
#OriginalFileList
#ParsedFileList

Author

Commented:
I got this Question solved my self
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.