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
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Can SQL7 examine a file directory listing?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-12 : 09:57:45
Shaun writes "My SQL7 is installed on a Windows NT 4 box.

I would like to create a SQL7 Stored Procedure that knows how to examine a directory listing of my ftproot directory. If files are there to be imported, the filenames will match a wildcard specification, but not an exact specification. The filenames will begin with 'CCYY-MM-DD' and will end with some arbitrary timestamp in HHMMDD format with a known extension.

The parameter to this stored procedure should be the date. The subsequent import process has already been written. However, it must know the exact filenames before it works.

Has anyone written a stored procedure that reads and examines the filenames within a directory?

Thanks,
Shaun"

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-07-12 : 10:26:11
SQL Server can execute shell commands through master.dbo.xp_cmdshell. You could use it to return a directory listing in the following way:


insert {table} (...)
exec master.dbo.xp_cmdshell 'dir c:\'
 


Jonathan Boott, MCDBA
Go to Top of Page

monkeybite
Posting Yak Master

152 Posts

Posted - 2002-07-12 : 10:28:43
I don't have a specific SPROC for you, but maybe this script will help you to get started:
CREATE TABLE #tmp (RowSet varchar(7500))
INSERT INTO #tmp (RowSet)
EXEC master.dbo.xp_cmdshell 'DIR C:\ /B'

SELECT * FROM #tmp
DROP TABLE #tmp
GO

You might be able to return more info about the files by fiddling with the switches on the DIR command.

-- monkey



Go to Top of Page
   

- Advertisement -