Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not sure how to describe this... sorry 2

Status
Not open for further replies.

Qmoto

MIS
Oct 21, 2004
74
US
I'm looking for a way to take a list of files and automatically import that information into an SQL database.

For example I have four or five hundred adobe acrobat files in a folder, with a new file automatically generated each morning.

What would I need to do in order to get the name of the file and the location of the file in the database, which I would then use to list the files on the intranet?
 
You can play with variations on this theme.
Code:
[Blue]CREATE[/Blue] [Blue]TABLE[/Blue] #Temp [Gray]([/Gray]Test [Blue]varchar[/Blue][Gray]([/Gray]200[Gray])[/Gray][Gray])[/Gray]
[Blue]INSERT[/Blue] [Blue]INTO[/Blue] #Temp
  [Blue]EXEC[/Blue] xp_cmdshell [red]'Dir *.*'[/red]
[Blue]SELECT[/Blue] [Gray]*[/Gray] [Blue]FROM[/Blue] #Temp
[Blue]DROP[/Blue] [Blue]TABLE[/Blue] #Temp
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Along the same theme:

Code:
--Use this to create table
create table filelist (lineitem varchar(255))
GO

--use this to populate on a daily basis
truncate table filelist
GO

insert into filelist
exec master..xp_cmdshell 'dir c:\mydirectory /B /S'
GO

delete
from filelist
where lineitem is null
GO

--Separate out the path and file name if you want.
select lineitem, 
replace(lineitem, reverse(left(reverse(lineitem), patindex('%\%', reverse(lineitem)) - 1)), '') as FPath,
reverse(left(reverse(lineitem), patindex('%\%', reverse(lineitem)) - 1)) as FName
from filelist
GO

Craig
 
When we do this, we write a vbscript program to put the directory list into a text file and then import the text file into the database.

The vbscript script I run (withthe terribly original name of run.html) is as follows
Code:
<script language="VBscript">	
    Dim objFilesys 
    Dim objFolder 
    Dim objFiles 
    Dim afiles 
    Dim txt 
    Set objFilesys = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFilesys.getFolder("C:\ImportData\Approach Plates")
    Set objFiles = objFolder.Files
    Set txt = objFilesys.createtextfile("C:\databases\ApproachPlates.txt", True)
    For Each afiles In objFiles
        'Debug.Print afiles.Name
        txt.writeline afiles.Name
    Next  
</script>

Just change your folder location and text file name to use.
Then I do a bunch of things in a DTS package to parse various other fields out of the data and import it into a table.

You could do this in a scheduled job if you need the steps to run on a regular schedule. Not sure exactly how you would schedule the vbscript to run without human interference but I think the netwrok operating system has a way to schedule tasks to run instead of using SQL Server jobs or possibly xp_cmdshell could handle it as a job step.

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
You guys are great!

I havent had a chnce to experiment just yet, but I'll let you know how it goes.

Thanks Again!
 
Thanks so much for the replies! I've had a grand total of twenty minuites to 'play' with this so far, and it its working, but I haven't made it to SQLSisters method yet I'm working on it though, actually sister :0) when I use the code you gave me I get an error in IE6
Code:
'ActiveX component can't create object: 'Scriptin.FileSystemObject'

Anyway, thanks again for the help!


Steve
 
Sorry, that's just my pathetic typing skills....

Here's how I'm trying to do it
Code:
<html>
<head></head>

<body>

<script language="VBscript">    
    Dim objFilesys
    Dim objFolder
    Dim objFiles
    Dim afiles
    Dim txt
    Set objFilesys = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFilesys.getFolder("C:\temp")
    Set objFiles = objFolder.Files
    Set txt = objFilesys.createtextfile("C:\temp\filelist.txt", True)
    For Each afiles In objFiles
        'Debug.Print afiles.Name
	   txt.writeline afiles.Name'
    Next  
</script>

</body>
</html>

I've tried the script in both head and body locations, I've given the asp.net userid read/write access to the directory, and this is the error I'm getting.
Code:
Internet Explorer
Problems with this Web page might provent it from being displayed properly...

Line: 7
Char: 5
Error: ActiveX component can't create object: 'Scripting.FileSystemObject'
Code: 0
URL: [URL unfurl="true"]http://barnsteadintranet.company.com/test.html[/URL]

I've also tried this in an .aspx page and a standard .htm page. btw, this is a IIS 5.0 on Win2k Server if that helps. Ohh, and I've also tried using the vb page language doctype just to make sure.
Code:
<%@ Page Language="VB" ContentType="text/html" %>

I'm sure it's something simple, and or, it's related to my lack of coding ability... :0)
 
OK I didn't create the script, one of our former programmers did. But I do not believe he used any html in it at all. He just named it .html so I could run it from my browser on my desktop. I opened the file in Notepad and what I gave you is absolutely everything in the file. I ran it on a desktop not a server. Maybe that's the issue?

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
This is security issue... when executed from IE, site URL must be in trusted zone, and/or creation of ActiveX controls must be enabled (without prompt).
 
Up to this point the code from clapag22 has worked the best for me, so for now I'll continue to use it - I've not yet been able to get the vb script working, however I do appreciate the help and the code SQLsister.

Thanks again everyone!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top