IF OBJECT_ID (N'dbo.RDYadav') IS NOT NULL
DROP PROCEDURE dbo.RDYadav
GO
CREATE PROCEDURE dbo.RDYadav
@FileSpec VARCHAR(2000),
@order VARCHAR (80) = '/O-D'
AS
DECLARE @myfiles TABLE (MyID INT IDENTITY(1,1) PRIMARY KEY, FullPath VARCHAR(2000))
DECLARE @CommandLine VARCHAR(4000)
IF @order IS NOT NULL
BEGIN
SELECT @CommandLine =LEFT('dir "' + @FileSpec + '" /A-D /B /S '+@order,4000)
INSERT INTO @MyFiles (FullPath)
EXECUTE xp_cmdshell @CommandLine
DELETE FROM @MyFiles WHERE fullpath IS NULL OR fullpath='File Not Found'
END
SELECT fullpath FROM @MyFiles
-------------------------------------------------------------
GO
EXECUTE RDYadav 'D:\*.txt'
DROP PROCEDURE dbo.RDYadav
GO
CREATE PROCEDURE dbo.RDYadav
@FileSpec VARCHAR(2000),
@order VARCHAR (80) = '/O-D'
AS
DECLARE @myfiles TABLE (MyID INT IDENTITY(1,1) PRIMARY KEY, FullPath VARCHAR(2000))
DECLARE @CommandLine VARCHAR(4000)
IF @order IS NOT NULL
BEGIN
SELECT @CommandLine =LEFT('dir "' + @FileSpec + '" /A-D /B /S '+@order,4000)
INSERT INTO @MyFiles (FullPath)
EXECUTE xp_cmdshell @CommandLine
DELETE FROM @MyFiles WHERE fullpath IS NULL OR fullpath='File Not Found'
END
SELECT fullpath FROM @MyFiles
-------------------------------------------------------------
GO
EXECUTE RDYadav 'D:\*.txt'
No comments:
Post a Comment