September 30, 2003 at 5:49 am
I need read all TXT files from the directory and save it on a file, How do I do that?
thanks
Nelson
September 30, 2003 at 6:14 pm
Do you need the contents of the files, or the filnames themselves? What "file" do you want to save the result to?
If you need to read the contents of multiple files from a directory into a table, check ut the following,
http://www.sqldts.com/default.aspx?246
Hope this helps
Phill Carter
--------------------
Colt 45 - the original point and click interface
--------------------
Colt 45 - the original point and click interface
October 1, 2003 at 1:05 pm
I just need the file names into to a table
October 1, 2003 at 5:43 pm
OK, is this a routine thing or one-off. What is the resulting table used for.
You can run a short VBScript that uses the filesystem object to iterate through a folder collection adding the entries into a table.
For a one off, you can use the DIR command to pipe the filenames into a text file and import that. eg: DIR *.txt /b > txtfilelist.lst
Hope this helps
Phill Carter
--------------------
Colt 45 - the original point and click interface
--------------------
Colt 45 - the original point and click interface
October 1, 2003 at 5:58 pm
Try this one...
EXEC master.dbo.xp_cmdshell 'DIR C:\ /b'
Gary Johnson
Microsoft Natural Language Group
DBA, Sr. DB Engineer
Gary Johnson
Microsoft Natural Language Group
DBA, Sr. DB Engineer
This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.
October 1, 2003 at 8:41 pm
quote:
I just need the file names into to a table
If you don't mind using an undocumented extended stored procedure:
CREATE PROC FileNames @dir varchar(200) AS
SET NOCOUNT ON
IF OBJECTPROPERTY(OBJECT_ID('Tbl_Files'),'isusertable') = 1
DROP TABLE Tbl_Files
CREATE TABLE #files(File_Name varchar(200), depth int, fil int)
INSERT #files
EXEC master.dbo.xp_dirtree @dir,1,1
SELECT File_Name
INTO Tbl_Files
FROM #files
WHERE fil = 1
Otherwise, if you allow such things:
CREATE PROC FileNames @dir varchar(200) AS
SET NOCOUNT ON
DECLARE @sql varchar(300)
SET @sql = 'dir ' + @dir + ' /b/a-d-s'
IF OBJECTPROPERTY(OBJECT_ID('Tbl_Files'),'isusertable') = 1
TRUNCATE TABLE Tbl_Files
ELSE CREATE TABLE Tbl_Files(File_Name varchar(200))
INSERT Tbl_Files
EXEC master.dbo.xp_cmdshell @sql
DELETE FROM Tbl_Files
WHERE File_Name IS NULL
--Jonathan
--Jonathan
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply