Reply to topic  [ 11 posts ] 
File exists in SQL 
Author Message
Occasionally has a life

Joined: Sat Nov 28, 2009 5:28 pm
Posts: 228
Reply with quote
HI,
can anyone help me? I am a trying to write a simple SQL script to check whether a file exists of not. I have tracked down xp_fileexist but this only seems to work in a root directory :( and all my files wil be in subdirectories... is there another command I am missing or is it not possible?

_________________
cheers
Rich

A Vision of a Champion is someone who is bent over, drenched with sweat, at the point of exhaustion, when no one else is watching


Wed Jul 07, 2010 11:34 am
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
I don't understand. Can you post what you've got so far? SQL is for querying and modifying databases - is this what you mean and if so can you outline your db structure?

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Wed Jul 07, 2010 1:00 pm
Profile
Occasionally has a life

Joined: Sat Nov 28, 2009 5:28 pm
Posts: 228
Reply with quote
What I have is a PDF path in a db record, for some reason a PDF hasn't been created and I am trying to track down easily a list of the missing PDFs,

so basically what I am trying to do is below in 'english'..

select * from table T1
where T1.PDF_Path doesn't exist

_________________
cheers
Rich

A Vision of a Champion is someone who is bent over, drenched with sweat, at the point of exhaustion, when no one else is watching


Wed Jul 07, 2010 1:06 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
My understanding is that the functionality isn't there. Yes you need the SQL to read the file names / paths out of the database, but there's no way to get SQL to loko through the file/folder structure. Any other programming language should be fine though.

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Wed Jul 07, 2010 1:11 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5150
Location: /dev/tty0
Reply with quote
You could try the xp_cmdshell command. You could then have this fire off a script which would allow you to use all the usual UNIX/Windows command line tools to search for files...


Wed Jul 07, 2010 1:14 pm
Profile WWW
Occasionally has a life

Joined: Sat Nov 28, 2009 5:28 pm
Posts: 228
Reply with quote
thanks guys, I was kinda figuring I was asking the impossible... guess i wil have to write a program to do it...

_________________
cheers
Rich

A Vision of a Champion is someone who is bent over, drenched with sweat, at the point of exhaustion, when no one else is watching


Wed Jul 07, 2010 1:38 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
It sounds perfectly scriptable, as Ben says.

You need a script that:

  1. Executes the SQL to get the file paths
  2. Grabs the results from the SQL
  3. For each file path
    1. Browses to see if the file exists
    2. If it doesn't add it to an output file

I don't have much experience of Windows scripting, but it'd be doable in Bash for example.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Wed Jul 07, 2010 2:27 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
EddArmitage wrote:
It sounds perfectly scriptable, as Ben says.

You need a script that:

  1. Executes the SQL to get the file paths
  2. Grabs the results from the SQL
  3. For each file path
    1. Browses to see if the file exists
    2. If it doesn't add it to an output file

I don't have much experience of Windows scripting, but it'd be doable in Bash for example.


bash, perl, a quick c# command line tool

sql wont help find the file, its a db language, you will just get the file name (possibly path)

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Wed Jul 07, 2010 11:00 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
finlay666 wrote:
sql wont help find the file, its a db language, you will just get the file name (possibly path)

Yup. My understanding was there's a DB with file paths in it somewhere, that needs querying first.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Thu Jul 08, 2010 7:54 am
Profile
Occasionally has a life

Joined: Sat Nov 28, 2009 5:28 pm
Posts: 228
Reply with quote
that is correct, xp_fileexists only works to a single level. I am, going to write a program in the app, it wil take a lot longer but that's the only solution with my limited sql knowledge.

thanks for the help everyone, I may revisit this when I have sometime to look into it properly...

_________________
cheers
Rich

A Vision of a Champion is someone who is bent over, drenched with sweat, at the point of exhaustion, when no one else is watching


Thu Jul 08, 2010 8:23 am
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 11:36 pm
Posts: 3527
Location: Portsmouth
Reply with quote
Image

That is all.

_________________
Image


Tue Aug 10, 2010 6:12 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.